How do you structure your API with channels? A com...
# coroutines
g
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
also
with(bar()) { foo() }
g
oh, so you actually use
with
sometimes, @gildor, got ya)
g
Yes, but only for nested scopes of extension functions, like in this case
s
Any extension lambda (lambda with a 'this' receiver) would work.
d
bar.foo(scope)
might be preferable