Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Last active February 22, 2021 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/b5914bbcfea8ea23642566e6093a2ca7 to your computer and use it in GitHub Desktop.
Save le0nidas/b5914bbcfea8ea23642566e6093a2ca7 to your computer and use it in GitHub Desktop.
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