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)ursus
04/02/2020, 10:11 PMstreetsofboston
04/02/2020, 10:27 PMursus
04/02/2020, 10:29 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/clientstreetsofboston
04/02/2020, 10:30 PMursus
04/02/2020, 10:31 PMursus
04/02/2020, 10:32 PMursus
04/02/2020, 10:33 PMursus
04/02/2020, 10:36 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.streetsofboston
04/02/2020, 11:04 PMursus
04/02/2020, 11:15 PMursus
04/02/2020, 11:17 PMursus
04/02/2020, 11:17 PM