bnn
10/02/2019, 10:19 PMclass Foo(ctx: CoroutineContext) {
val scope = CoroutineScope(ctx)
fun launchSome() = scope.launch { ... }
}
Are there better ways or conventions to do that?
I wonder some possibilities such as ...
- To implement CoroutineScope ( class Foo(ctx: CoroutineContext = ... : CoroutineScope { ... }
)
- To define method as CoroutineScope extension function ( fun CoroutineScope.launchSome() = launch(ctx) {...}
)
Thanks.gildor
10/03/2019, 10:22 AMbnn
10/03/2019, 2:34 PMclass Foo(private val scope: CoroutineScope) {
fun launchSome() = scope.launch { ... }
}
Is my understanding correct?Luis Munoz
10/03/2019, 3:12 PMbnn
10/04/2019, 3:01 AMgildor
10/04/2019, 3:30 AMlaunchSome
is public, are you sure that you need scope in Foo? Maybe just pass it to launchSome, or, even better, just make it suspend and let user of this function decide about target scope