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. // Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit") 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 { application {

View File

@ -3,13 +3,30 @@
*/ */
package xyz.etztech.stonks package xyz.etztech.stonks
class App { import io.javalin.Javalin
val greeting: String import kotlinx.coroutines.*
get() {
return "Hello World!"
}
}
fun main() { 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)
}
}
} }