Last active
January 11, 2024 14:31
-
-
Save itsandreramon/dcda3ba9b7816dbc2287a98c550b8aa3 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
@SingleIn(AppScope::class) | |
class UserSessionManager @Inject constructor(private val app: App) { | |
private var _userCoroutineScope: UserCoroutineScope? = null | |
private val userCoroutineScope: CoroutineScope | |
get() = createUserCoroutineScope() | |
fun resetSession() { | |
_userCoroutineScope?.cancel() | |
_userCoroutineScope = null | |
userComponent = null | |
} | |
fun createSession(id: String) { | |
val session = UserSession(id) | |
userComponent = app.appComponent | |
.userComponentFactory() | |
.create(session, userCoroutineScope) | |
} | |
private fun createUserCoroutineScope(): UserCoroutineScope { | |
return _userCoroutineScope ?: UserCoroutineScope(CoroutineScope(SupervisorJob())) | |
.also { _userCoroutineScope = it } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment