ursus
08/13/2019, 3:43 PMMarko Mitic
08/13/2019, 3:44 PMview
will be kept until scope is canceled or coroutine completesursus
08/13/2019, 3:45 PMview
, but whole this
(viewModel) right?Marko Mitic
08/13/2019, 3:47 PMview
was a variable inside doSomething()
fun it shouldn't leak entire ViewModel (someone correct me if I'm wrong), not sure what happens if view
is a property (it will probably keep reference to this/ViewModel to access it)voben
08/13/2019, 3:50 PMglobalScope.launch
will cause a leak if the operation is not completed when VM is disposed.ursus
08/13/2019, 3:51 PMlouiscad
08/13/2019, 3:53 PMviewModelScope
in KTX artifact (which is possibly still in beta/rc).voben
08/13/2019, 3:56 PMursus
08/13/2019, 3:57 PMlouiscad
08/13/2019, 3:58 PMursus
08/13/2019, 3:59 PMursus
08/13/2019, 4:02 PMlouiscad
08/13/2019, 4:03 PMjoin
a Job
`launch`ed from another scope, and cancelling the coroutine calling join
should not cancel the Job
.ursus
08/13/2019, 4:05 PMursus
08/13/2019, 4:11 PMsuspend fun doSomething(): String = scoped x@{
delay(2000)
Log.d("Default", "returning something")
foo()
Log.d("Default", "returning something 2")
return@x "Something"
}
priva
te suspend fun <T> scoped(body: suspend CoroutineScope.() -> T): T {
val deferred = scope.async(block = body)
return deferred.await()
}
louiscad
08/13/2019, 4:27 PMursus
08/13/2019, 7:55 PMlouiscad
08/13/2019, 7:59 PMcreateScope(activeWhile = <http://Lifecycle.State.XXX|Lifecycle.State.XXX>)
extension function for Lifecycle
, you can have it, even for ProcessLifecycle
. You can find that extension here: https://github.com/LouisCAD/Splitties/tree/master/modules/lifecycle-coroutinesursus
08/13/2019, 8:35 PMlouiscad
08/13/2019, 8:45 PMursus
08/13/2019, 10:27 PM