Last active
February 18, 2021 00:46
-
-
Save recheej/36a9f9006169ca36c280bf985036702b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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