Skip to content

Instantly share code, notes, and snippets.

@recheej
Last active February 18, 2021 00:46
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 recheej/36a9f9006169ca36c280bf985036702b to your computer and use it in GitHub Desktop.
Save recheej/36a9f9006169ca36c280bf985036702b to your computer and use it in GitHub Desktop.
fun performNetworkRequest(cont: Continuation<Unit>): Any? {
val stateMachine = object: ContinuationImpl<Unit> {
var label = 0
override fun resumeWith(...) {
performNetworkRequest(this) // call with this state machine again
}
}
var response: Response? = null
switch(stateMachine.label) {
case 0:
stateMachine.label = 1 // set next state of state machine
response = getResponse('https://blah.com', stateMachine)
break
case 1:
stateMachine.label = 2 // set next state of state machine
storeResponseInDatabase(response, stateMachine)
return Unit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment