Last active
March 18, 2020 11:14
-
-
Save manuelvicnt/eb4cb59ee60b7ce79927db89ab1b110e to your computer and use it in GitHub Desktop.
LoginUser suspend fun (compiler generated code)
This file contains hidden or 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
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
fun loginUser(userId: String?, password: String?, completion: Continuation<Any?>) { | |
... | |
val continuation = completion as? LoginUserStateMachine ?: LoginUserStateMachine(completion) | |
when(continuation.label) { | |
0 -> { | |
// Checks for failures | |
throwOnFailure(continuation.result) | |
// Next time this continuation is called, it should go to state 1 | |
continuation.label = 1 | |
// The continuation object is passed to logUserIn to resume | |
// this state machine's execution when it finishes | |
userRemoteDataSource.logUserIn(userId!!, password!!, continuation) | |
} | |
1 -> { | |
// Checks for failures | |
throwOnFailure(continuation.result) | |
// Gets the result of the previous state | |
continuation.user = continuation.result as User | |
// Next time this continuation is called, it should go to state 2 | |
continuation.label = 2 | |
// The continuation object is passed to logUserIn to resume | |
// this state machine's execution when it finishes | |
userLocalDataSource.logUserIn(continuation.user, continuation) | |
} | |
... // leaving out the last state on purpose | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment