Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun delay(delayTime: Long, stateMachine: StateMachine) {
Thread.sleep(delayTime)
stateMachine.resume()
}
class StateMachine {
var state = 0
var start = 0L
fun resume() {
when (state) {
0 -> {
start = System.currentTimeMillis()
state++
println("start")
delay(1000L, this)
}
1 -> {
state++
println("end ${System.currentTimeMillis() - start}")
}
}
}
}
fun main(args: Array<String>) {
val stateMachine = StateMachine()
stateMachine.resume()
}
import kotlinx.coroutines.experimental.delay
suspend fun simpleCoroutine() {
val start = System.currentTimeMillis()
println("start")
delay(1000)
println("end ${System.currentTimeMillis() - start}")
}
@sys1yagi
Copy link
Author

sys1yagi commented Aug 18, 2018

You can run on try kotlin.
https://try.kotlinlang.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment