Pulls one message from the communication channel, when it becomes available.
Pulls one message from the communication channel, when it becomes available.
Example:
import cats.implicits._ import cats.effect.Async def sum[F[_]](channel: ConsumerF[F, Int, Int], acc: Long = 0) (implicit F: Async[F]): F[Long] = { channel.pull.flatMap { case Left(e) => F.pure(acc + e) case Right(i) => sum(channel, acc + i) } }
either Left(e)
, if the channel was closed with a final e
completion event, or Right(a)
, representing a message that
was pulled from the channel
Pulls a whole batch of messages from the channel, at least one,
the returned sequence being no larger than the specified maxLength
.
Pulls a whole batch of messages from the channel, at least one,
the returned sequence being no larger than the specified maxLength
.
import cats.implicits._ import cats.effect.Async def sum[F[_]](channel: ConsumerF[F, Int, Int], acc: Long = 0) (implicit F: Async[F]): F[Long] = { channel.pullMany(1, 16).flatMap { case Left(e) => F.pure(acc + e) case Right(seq) => sum(channel, acc + seq.sum) } }
is the minimum size of the returned sequence; for as long as the channel isn't halted, the returned task will back-pressure until the required number of events have been collected
is the maximum size of the returned sequence;
for fairness purposes (e.g. multiple workers consuming from
the same ConsumerF
), a smaller value is recommended,
or otherwise Int.MaxValue
can be used
either Left(e)
, if the channel was closed with a final e
completion event, or Right(seq)
, representing a non-empty
sequence of messages pulled from the channel, but that is
no larger than maxLength
A simple interface that models the consumer side of a producer-consumer communication channel.
Currently exposed by ConcurrentChannel.consume.
is effect type used for processing tasks asynchronously
is the type for the completion event
is the type for the stream of events being consumed