is a channel always first in first out? Can I rece...
# coroutines
z
is a channel always first in first out? Can I receive from a channel based on a filter, and if that filter fails to pass, leave those items in that channel? I have
Channel<T>
, and that
T
has two subclasses,
T.One
and
T.Two
. I need the first emission of
T.Two
to initialize some state in a coroutine, and after that I want to observe all emissions of
T
. But if
T.One
emits first, I want to queue it up (leave it in the channel), and allow it to emit once the first instance of
T.Two
finishes emitting.
z
Yes, a channel is basically just a queue with a bunch of lock-free thread safety built-in. It would probably hugely complicate the implementation to allow random access or stuff like this. But you could emulate this behavior by having two channels as a pipeline, reading from one and forwarding all `Two`s into the other.
Flow would be even better, but you’d need multicasting operators 😞
👍 1
z
what I’m going to do is just create a function that returns an object that can do what I want
r
Hmm the example you left is abit confusing. T owns the two subclasses . So every instance that is emitted will have both T.one and T.two , no?
z
T
is a sealed class
r
Or a flow