forked from Minecraft/Stonks
Include Javalin and add a periodic function
parent
af99bfd2b1
commit
5cb1d9a4bc
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue