1
0
Fork 0

Include Javalin and add a periodic function

main
Kevin Belisle 2021-06-25 15:56:20 -04:00
parent af99bfd2b1
commit 5cb1d9a4bc
2 changed files with 30 additions and 7 deletions

View File

@ -34,6 +34,12 @@ dependencies {
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
compile("org.slf4j:slf4j-simple:1.7.30")
compile("io.javalin:javalin:3.13.8")
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
}
application {

View File

@ -3,13 +3,30 @@
*/
package xyz.etztech.stonks
class App {
val greeting: String
get() {
return "Hello World!"
}
}
import io.javalin.Javalin
import kotlinx.coroutines.*
fun main() {
println(App().greeting)
println("Starting Stonks...")
var apiServerPort = 7000
initApiServer(apiServerPort)
var periodicFetchingInterval = 1000L
initPeriodicFetching(periodicFetchingInterval)
}
fun initApiServer(apiServerPort: Int) {
val app = Javalin.create().start(apiServerPort)
app.get("/") { ctx -> ctx.result("Hello World") }
}
fun initPeriodicFetching(interval: Long) =
runBlocking {
launch {
while (true) {
println("Stonks!")
delay(interval)
}
}
}