Last active
February 22, 2021 21:26
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
class State( | |
var label: Int = 0, | |
var result: Any? = null | |
) | |
fun saveUserTasks(userId: Int, state: State) { | |
when (state.label) { | |
0 -> { | |
val user = loadUser(userId) | |
println("user loaded") | |
state.result = user | |
// pause execution | |
} | |
1 -> { | |
// resume execution | |
val user = state.result as User | |
val tasks = loadTasks(user) | |
println("tasks loaded") | |
state.result = tasks | |
// pause execution | |
} | |
2 -> { | |
// resume execution | |
val tasks = state.result as List<Task> | |
saveTasks(tasks) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment