class SaveUserTasks : Coroutine() { | |
operator fun invoke(userId: Int) { | |
saveUserTasks(userId, state) | |
} | |
private fun saveUserTasks(userId: Int, state: State) { | |
when (state.label) { | |
0 -> { | |
val user = loadUser(userId) | |
println("user loaded") | |
resumeWith(user) | |
return | |
} | |
1 -> { | |
val user = restore<User>() | |
val tasks = loadTasks(user) | |
println("tasks loaded") | |
resumeWith(tasks) | |
return | |
} | |
2 -> { | |
val tasks = restore<List<Task>>() | |
saveTasks(tasks) | |
finish() | |
} | |
} | |
} | |
} | |
class ApplyDownloadedSettings : Coroutine() { | |
operator fun invoke() { | |
applyDownloadedSettings(state) | |
} | |
private fun applyDownloadedSettings(state: State) { | |
when (state.label) { | |
0 -> { | |
val settings = downloadSettings() | |
println("settings downloaded") | |
resumeWith(settings) | |
return | |
} | |
1 -> { | |
val settings = restore<Settings>() | |
applySettings(settings) | |
println("setting applied") | |
finish() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment