Last active
August 18, 2018 07:25
-
-
Save sys1yagi/2ec9f74438333feff0be8cc6134812dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.delay | |
suspend fun simpleCoroutine() { | |
val start = System.currentTimeMillis() | |
println("start") | |
delay(1000) | |
println("end ${System.currentTimeMillis() - start}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run on try kotlin.
https://try.kotlinlang.org/