https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

ghedeon

01/17/2019, 10:03 AM
How do you structure your API with channels? A common example from docs is
Copy code
fun CoroutineScope.foo(): ReceiveChannel<Int> = produce {}
What if it's in a different class? Then the usage is ... strange? 🙂
Copy code
class Bar{
fun CoroutineScope.foo(): ReceiveChannel<Int> = produce {}
}

.... coroutine scope ....
bar().run {
   foo() ??
}
g

gildor

01/17/2019, 10:07 AM
also
with(bar()) { foo() }
g

ghedeon

01/17/2019, 10:08 AM
oh, so you actually use
with
sometimes, @gildor, got ya)
g

gildor

01/17/2019, 10:09 AM
Yes, but only for nested scopes of extension functions, like in this case
s

streetsofboston

01/17/2019, 12:43 PM
Any extension lambda (lambda with a 'this' receiver) would work.
d

Dico

01/17/2019, 3:57 PM
bar.foo(scope)
might be preferable
4 Views