Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created February 22, 2021 20:38
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 le0nidas/90244297fd7347c5e48555ca68abe3b4 to your computer and use it in GitHub Desktop.
Save le0nidas/90244297fd7347c5e48555ca68abe3b4 to your computer and use it in GitHub Desktop.
fun saveUserTasks(userId: Int, state: State) {
when (state.label) {
0 -> {
val user = loadUser(userId)
println("user loaded")
state.result = user
state.label = 1
return
}
1 -> {
// resume execution
val user = state.result as User
val tasks = loadTasks(user)
println("tasks loaded")
state.result = tasks
state.label = 2
return
}
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