This repository has been archived on 2024-09-12. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
wrench/src/main/kotlin/xyz/atnrch/wrench/scheduler/Watcher.kt
2022-11-13 23:01:59 +01:00

31 lines
No EOL
684 B
Kotlin

package xyz.atnrch.wrench.scheduler
import kotlinx.coroutines.*
import kotlinx.coroutines.swing.Swing
import java.util.concurrent.TimeUnit
class Watcher {
companion object {
var WATCHING = false
}
private var coroutineScope = CoroutineScope(Dispatchers.Swing)
fun start() {
if(WATCHING) return
coroutineScope.launch {
WATCHING = true
while (WATCHING) {
delay(TimeUnit.SECONDS.toMillis(5))
println("Hello world!")
}
}
}
fun stop() {
coroutineScope.cancel()
coroutineScope = CoroutineScope(Dispatchers.Main)
WATCHING = false
}
}