ursus
04/02/2020, 9:57 PMsuspend fun someAction() = coroutineScope {
...
}
streetsofboston
04/02/2020, 10:01 PMursus
04/02/2020, 10:09 PMrepoScope.async {}.await()
inside a suspend function
I've never seen this, is this idiomatic? (that its inside a suspend fun is what gets me)streetsofboston
04/02/2020, 10:27 PMursus
04/02/2020, 10:29 PMstreetsofboston
04/02/2020, 10:30 PMrepoScope.async { doSomething() }.await()
, the doSomething
will not be cancelled even if the caller of repoScope.async
has ended (the await()
call, which will run in _caller_’s scope, will be cancelled asap).
You can hide the reposScope
inside the Repo-class and make it somewhat invisible to the caller/clientursus
04/02/2020, 10:31 PMstreetsofboston
04/02/2020, 11:03 PMGlobalScope
. Their lifecycle only ends when the app/process ends, not before that.
But if you have a, for example a User-Cache (that would behave like the cache with its own lifecyle that I described earlier), this user-cache’s lifecycle could end when the user logs out, zapping the cache and cancelling any related network-requests that are still queued/outstanding.ursus
04/02/2020, 11:15 PM