ox.channels

package ox.channels

Members list

Type members

Classlikes

class Channel[T](capacity: Int) extends Source[T], Sink[T]

Channel is a thread-safe data structure which exposes three basic operations:

Channel is a thread-safe data structure which exposes three basic operations:

  • send-ing a value to the channel. Values can't be null.
  • receive-ing a value from the channel
  • closing the channel using done or error

There are three channel flavors:

  • rendezvous channels, where senders and receivers must meet to exchange values
  • buffered channels, where a given number of sent values might be buffered, before subsequent sends block
  • unlimited channels, where an unlimited number of values might be buffered, hence send never blocks

Channels can be created using the channel's companion object. When no arguments are given, a rendezvous channel is created, while a buffered channel can be created by providing a positive integer to the Channel.apply method. A rendezvous channel behaves like a buffered channel with buffer size 0. An unlimited channel can be created using Channel.unlimited.

In a rendezvous channel, senders and receivers block, until a matching party arrives (unless one is already waiting). Similarly, buffered channels block if the buffer is full (in case of senders), or in case of receivers, if the buffer is empty and there are no waiting senders.

All blocking operations behave properly upon interruption.

Channels might be closed, either because no more values will be produced by the source (using done), or because there was an error while producing or processing the received values (using error).

After closing, no more values can be sent to the channel. If the channel is "done", any pending sends will be completed normally. If the channel is in an "error" state, pending sends will be interrupted and will return with the reason for the closure.

In case the channel is closed, one of the ChannelClosed values are returned. These can be converted to an exception by calling orThrow on a result which includes ChannelClosed as one of the components of the union type.

Type parameters

T

The type of the values processed by the channel.

Attributes

Companion
object
Supertypes
trait Sink[T]
trait Source[T]
trait SourceOps[T]
class Object
trait Matchable
class Any
Show all
object Channel

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Channel.type
sealed trait ChannelClosed

Returned by channel methods (e.g. Source.receive, Sink.send, select) when the channel is closed.

Returned by channel methods (e.g. Source.receive, Sink.send, select) when the channel is closed.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Done.type
class Error
object ChannelClosed

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
enum ChannelClosedException(cause: Option[Throwable]) extends Exception

Attributes

Supertypes
trait Enum
trait Product
trait Equals
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
case Error
case Done
case class Default[T](value: T) extends SelectClause[T]

A default clause, which will be chosen if no other clause can be selected immediately, during a select call.

A default clause, which will be chosen if no other clause can be selected immediately, during a select call.

There should be at most one default clause, and it should always come last in the list of clauses.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait SelectClause[T]
class Object
trait Matchable
class Any
Show all
case class DefaultResult[T](value: T) extends SelectResult[T]

The result returned in case a Default clause was selected in select.

The result returned in case a Default clause was selected in select.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait SelectResult[T]
class Object
trait Matchable
class Any
Show all
sealed trait SelectClause[+T]

A clause to use as part of select. Clauses can be created having a channel instance, using Source.receiveClause and Sink.sendClause.

A clause to use as part of select. Clauses can be created having a channel instance, using Source.receiveClause and Sink.sendClause.

A clause instance is immutable and can be reused in multiple select calls.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Receive
class Send
class Default[T]
sealed trait SelectResult[+T]

Results of a select call, when clauses are passed (instead of a number of Sources). Each result corresponds to a clause, and can be pattern-matched (using a path-dependent type)) to inspect which clause was selected.

Results of a select call, when clauses are passed (instead of a number of Sources). Each result corresponds to a clause, and can be pattern-matched (using a path-dependent type)) to inspect which clause was selected.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Received
class Sent
class DefaultResult[T]
trait Sink[-T]

A channel sink, which can be used to send values to the channel. See Channel for more details.

A channel sink, which can be used to send values to the channel. See Channel for more details.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Channel[T]
trait Source[+T] extends SourceOps[T]

A channel source, which can be used to receive values from the channel. See Channel for more details.

A channel source, which can be used to receive values from the channel. See Channel for more details.

Attributes

Companion
object
Supertypes
trait SourceOps[T]
class Object
trait Matchable
class Any
Known subtypes
class Channel[T]
object Source extends SourceCompanionOps

Various operations which allow creating Source instances.

Various operations which allow creating Source instances.

Some need to be run within a concurrency scope, such as supervised.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Source.type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Source.type
trait SourceOps[+T]

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Source[T]
class Channel[T]
Self type
Source[T]
object StageCapacity

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Types

opaque type StageCapacity

Value members

Concrete methods

def select(clause1: SelectClause[_], clause2: SelectClause[_]): Result | Result | ChannelClosed

Attributes

See also
def select(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_]): Result | Result | Result | ChannelClosed

Attributes

See also
def select[T1, T2](source1: Source[T1], source2: Source[T2]): T1 | T2 | ChannelClosed

Attributes

See also
def select[T1, T2, T3](source1: Source[T1], source2: Source[T2], source3: Source[T3]): T1 | T2 | T3 | ChannelClosed

Attributes

See also
def select[T](clauses: List[SelectClause[T]]): SelectResult[T] | ChannelClosed

Select exactly one clause to complete. Each clause should be created for a different channel.

Select exactly one clause to complete. Each clause should be created for a different channel.

If a couple of the clauses can be completed immediately, the select is biased towards the clauses that appear first.

If no clauses are given, or all clauses become filtered out, returns ChannelClosed.Done.

If a receive clause is selected for a channel that is done, select restarts, unless the clause is created with Source.receiveOrDoneClause.

Value parameters

clauses

The clauses, from which one will be selected.

Attributes

Returns

The result returned by the selected clause, wrapped with SelectResult, or a ChannelClosed, when any of the channels is closed (done or in error), and the select doesn't restart.

def select[T](sources: List[Source[T]])(using DummyImplicit): T | ChannelClosed

Same as select, but accepts Sources directly (without the need to create receive clauses), and wraps the result.

Same as select, but accepts Sources directly (without the need to create receive clauses), and wraps the result.

Attributes

Extensions

Extensions

extension [T](v: T | ChannelClosed)
inline def isValue: Boolean
inline def map[U](f: T => U): U | ChannelClosed
inline def orThrow: T

Throw a ChannelClosedException if the provided value represents a closed channel (one of ChannelClosed values).

Throw a ChannelClosedException if the provided value represents a closed channel (one of ChannelClosed values).

Attributes