Skip to content

Instantly share code, notes, and snippets.

@chaxiu
Created October 18, 2020 12:04
Show Gist options
  • Save chaxiu/fe245dd2c622ba4504eb9a0edcb5bf01 to your computer and use it in GitHub Desktop.
Save chaxiu/fe245dd2c622ba4504eb9a0edcb5bf01 to your computer and use it in GitHub Desktop.
when (continuation.label) {
0 -> {
// check exceptions
throwOnFailure(result)
log("start")
// Assign 1 to label, ready for the next state
continuation.label = 1
// Call getUserInfo()
suspendReturn = getUserInfo(continuation)
// Determine if it suspended
if (suspendReturn == sFlag) {
return suspendReturn
} else {
result = suspendReturn
//go to next state
}
}
1 -> {
throwOnFailure(result)
// Get user value from result
user = result as String
log(user)
// Saving user value in continuation
continuation.mUser = user
// Ready for next state
continuation.label = 2
// Call getFriendList
suspendReturn = getFriendList(user, continuation)
// Determine if it suspended
if (suspendReturn == sFlag) {
return suspendReturn
} else {
result = suspendReturn
//go to next state
}
}
2 -> {
throwOnFailure(result)
user = continuation.mUser as String
// Get friendList value from result
friendList = result as String
log(friendList)
// Saving values in continuation
continuation.mUser = user
continuation.mFriendList = friendList
// Ready for next state
continuation.label = 3
// Call getFeedList
suspendReturn = getFeedList(friendList, continuation)
// Determine if it suspended
if (suspendReturn == sFlag) {
return suspendReturn
} else {
result = suspendReturn
//go to next state
}
}
3 -> {
throwOnFailure(result)
user = continuation.mUser as String
friendList = continuation.mFriendList as String
feedList = continuation.result as String
log(feedList)
loop = false
}
}
@DALDEI
Copy link

DALDEI commented Jan 29, 2022

You are correct, this is the best explanation of CoRoutines I have ever read, at a level of technical detail that uniquely doesn't require the same level of prior knowledge to understand it.
3 years now working with coroutines -- and I previously knew all of the individual details presented (and much more), but I did not understand them as well before.
Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment