Created
February 22, 2021 21:09
-
-
Save le0nidas/81921bb7cb712ea9ba51eb8d45e72634 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
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