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
abstract class Coroutine { | |
var isFinished: Boolean = false | |
private set | |
protected val state: State by lazy { State() } | |
protected fun resumeWith(result: Any) { | |
state.label++ | |
state.result = result | |
} | |
protected fun <T> restore(): T { | |
return state.result as T | |
} | |
protected fun finish() { | |
state.label++ | |
isFinished = true | |
} | |
protected class State( | |
var label: Int = 0, | |
var result: Any? = null | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment