Skip to content

Instantly share code, notes, and snippets.

@itsandreramon
Last active January 11, 2024 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsandreramon/3ad336961a2e3a2917917d33e2342e3d to your computer and use it in GitHub Desktop.
Save itsandreramon/3ad336961a2e3a2917917d33e2342e3d to your computer and use it in GitHub Desktop.
@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
// ...
}
fun createSession(id: String) {
// ...
}
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