sealed trait Channel[F[_], A] extends AnyRef
Stream aware, multiple producer, single consumer closeable channel.
- Source
- Channel.scala
- Alphabetic
- By Inheritance
- Channel
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def close: F[Either[Closed, Unit]]
This method achieves graceful shutdown: when the channel gets closed,
stream
will terminate naturally after consuming all currently enqueued elements, including the ones by producers blocked on a bound.This method achieves graceful shutdown: when the channel gets closed,
stream
will terminate naturally after consuming all currently enqueued elements, including the ones by producers blocked on a bound."Termination" here means that
stream
will no longer wait for new elements on the channel, and not that it will be interrupted while performing another action: if you want to interruptstream
immediately, without first processing enqueued elements, you should useinterruptWhen
on it instead.After a call to
close
, any further calls tosend
orclose
will be no-ops.Note that
close
does not automatically unblock producers which might be blocked on a bound, they will only become unblocked ifstream
is executing.In other words, if
close
is called whilestream
is executing, blocked producers will eventually become unblocked, beforestream
terminates and furthersend
calls become no-ops. However, ifclose
is called afterstream
has terminated (e.g because it was interrupted, or had a.take(n)
), then blocked producers will stay blocked unless they get explicitly unblocked, either by a further call tostream
to drain the channel, or by a arace
withclosed
. - abstract def closed: F[Unit]
Semantically blocks until the channel gets closed.
- abstract def isClosed: F[Boolean]
Returns true if this channel is closed
- abstract def send(a: A): F[Either[Closed, Unit]]
Sends an element through this channel.
Sends an element through this channel.
It can be called concurrently by multiple producers, and it may semantically block if the channel is bounded or synchronous.
No-op if the channel is closed, see close for further info.
- abstract def sendAll: Pipe[F, A, Nothing]
Sends all the elements of the input stream through this channel, and closes it after.
Sends all the elements of the input stream through this channel, and closes it after. Especially useful if the channel is single producer.
- abstract def stream: Stream[F, A]
The stream of elements sent through this channel.
The stream of elements sent through this channel. It terminates if close is called and all elements in the channel have been emitted (see close for futher info).
This method CANNOT be called concurrently by multiple consumers, if you do so, one of the consumers might become permanently deadlocked.
It is possible to call
stream
again once the previous one has terminated, but be aware that some element might get lost in the process, e.g if the first call tostream
got 5 elements off the channel, and terminated after emitting 2, when the second call tostream
starts it won't see those 3 elements.Every time
stream
is pulled, it will serve all the elements that are queued up in a single chunk, including those from producers that might be semantically blocked on a bounded channel, which will then become unblocked. That is, a bound on a channel represents the maximum number of elements that can be queued up before a producer blocks, and not the maximum number of elements that will be received bystream
at once. - abstract def trySend(a: A): F[Either[Closed, Boolean]]
Attempts to send an element through this channel, and indicates if it succeeded (
true
) or not (false
).Attempts to send an element through this channel, and indicates if it succeeded (
true
) or not (false
).It can be called concurrently by multiple producers, and it may not succeed if the channel is bounded or synchronous. It will never semantically block.
No-op if the channel is closed, see close for further info.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])