Skip to content

Instantly share code, notes, and snippets.

@sys1yagi
Last active August 18, 2018 07:25
Show Gist options
  • Save sys1yagi/2ec9f74438333feff0be8cc6134812dd to your computer and use it in GitHub Desktop.
Save sys1yagi/2ec9f74438333feff0be8cc6134812dd to your computer and use it in GitHub Desktop.
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

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