Last active
September 14, 2022 10:21
-
-
Save aleksandarzekovic/a612355a05b330d0934fc5ce0d053f86 to your computer and use it in GitHub Desktop.
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
// The initial state of the state machine | |
int label = 0 | |
A a = null | |
B b = null | |
void resumeWith(Object result) { | |
if (label == 0) goto L0 | |
if (label == 1) goto L1 | |
if (label == 2) goto L2 | |
else throw IllegalStateException("call to 'resume' before 'invoke' with coroutine") | |
L0: | |
// result is expected to be `null` at this invocation | |
label = 1 | |
// 'this' is passed as a continuation | |
result = getRandomNum(this) | |
if (result == COROUTINE_SUSPENDED) return | |
L1: | |
A a = (A) result | |
label = 2 | |
val result = getSqrt(a, this) // 'this' is passed as a continuation | |
if (result == COROUTINE_SUSPENDED) return | |
L2: | |
B b = (B) result | |
log(String.valueOf(b)) | |
label = -1 // No more steps are allowed | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment