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