Created
November 14, 2019 13:38
-
-
Save manuelvicnt/19307282cbf287cfe74e1d9576139fd8 to your computer and use it in GitHub Desktop.
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 */ | |
class FirebaseAuthStateUserDataSource(...) : AuthStateUserDataSource { | |
private val channel = ConflatedBroadcastChannel<Result<AuthenticatedUserInfo>>() | |
private val listener: ((FirebaseAuth) -> Unit) = { auth -> | |
// Data processing logic | |
// Send the current user for observers | |
if (!channel.isClosedForSend) { | |
channel.offer(Success(FirebaseUserInfo(auth.currentUser))) | |
} else { | |
unregisterListener() | |
} | |
} | |
@Synchronized | |
override fun getBasicUserInfo(): Flow<Result<AuthenticatedUserInfo>> { | |
if (!isListening) { | |
firebase.addAuthStateListener(listener) | |
isListening = true | |
} | |
return channel.asFlow() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment