Let’s say I have a `CoroutineScope` backed by a mu...
# coroutines
z
Let’s say I have a
CoroutineScope
backed by a multi-thread dispatcher. I also have a
Channel<Int>
that needs to receive incoming messages.
Copy code
val scope = CoroutineScope(Dispatchers.Default)
val channel: Channel<Int> = TODO()

fun onNewInt launch`(newInt: Int) {
  // `newInt` is delivered from outside a coroutine
  // what is the appropriate way to emit to the channel? 
}
I see two possibilities (see code snippet)
2️⃣ 1
1️⃣ 2
vote
1
or
2
for preferred approach
w
Depending on your case of course, but
UNLIMITED
may not be what you want if you have slow consumers
maybe you want 500 items or something, that is if you went with option 2
o
really depends on how you want the channel to operate. if you're aiming for an unlimited back-log, I would vote for 2, as it's more explicit about that. but if you want backpressure, I would set RENDEZVOUS/specific count, and use
sendBlocking
rather than offer
👍 1
g
It's purely depends on semantics which you want
👍 1
z
There's no guarantee on ordering though with
scope.launch { }
👌 1