ox.channels

package ox.channels

Members list

Type members

Classlikes

object Actor

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Actor.type
class ActorRef[T](c: Sink[T => Unit])

Attributes

Supertypes
class Object
trait Matchable
class Any

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
class Channel[T] 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. A rendezvous channel is created using Channel.rendezvous. A buffered channel can be created either with a given capacity - by providing a positive integer to the Channel.buffered method - or with the default capacity (BufferCapacity.default) using Channel.bufferedDefault . 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, a ChannelClosedException is thrown. Alternatively, you can use the orClosed method variants (e.g. sendOrClosed, receiveOrClosed), which don't throw exceptions, but return a union type which includes one of ChannelClosed values. Such a union type can be further converted to an exception, Either or Try using one of the extension methods in ChannelClosedUnion.

Type parameters

T

The type of the values processed by the channel.

Attributes

Companion
object
Supertypes
trait Sink[T]
trait Source[T]
trait SourceDrainOps[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.receiveOrClosed, Sink.sendOrClosed, selectOrClosed) when the channel is closed.

Returned by channel methods (e.g. Source.receiveOrClosed, Sink.sendOrClosed, selectOrClosed) when the channel is closed.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Done
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
class Error
class Done

Extension methods on union types which includes ChannelClosed.

Extension methods on union types which includes ChannelClosed.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
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], SourceDrainOps[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 SourceDrainOps[T]
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
trait SourceDrainOps[+T]

Attributes

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

Attributes

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

Types

opaque type BufferCapacity

Used to determine the capacity of buffers, when new channels are created by channel or flow-transforming operations, such as Source.map, Flow.buffer, Flow.runToChannel. If not in scope, the default of 16 is used.

Used to determine the capacity of buffers, when new channels are created by channel or flow-transforming operations, such as Source.map, Flow.buffer, Flow.runToChannel. If not in scope, the default of 16 is used.

Attributes

Value members

Concrete methods

def forkPropagate[T](propagateExceptionsTo: Sink[_])(f: => Unit)(using OxUnsupervised): Unit

Fork the given computation, propagating any exceptions to the given sink. The propagated exceptions are not rethrown. The fork is run only for its side effects, and the result is discarded (can't be joined, same as forkDiscard).

Fork the given computation, propagating any exceptions to the given sink. The propagated exceptions are not rethrown. The fork is run only for its side effects, and the result is discarded (can't be joined, same as forkDiscard).

Designed to be used in stream operators.

Attributes

See also

ADR#1, ADR#3, implementation note in SourceOps.

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

Attributes

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

Attributes

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

Attributes

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

Attributes

See also
def select[T](clauses: Seq[SelectClause[T]]): SelectResult[T]

Select exactly one clause to complete. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one clause to complete. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

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, returns ChannelClosed.Done.

For a variant which doesn't throw exceptions when any of the channels is closed, use selectOrClosed.

Value parameters

clauses

The clauses, from which one will be selected.

Attributes

Returns

The result returned by the selected clause, wrapped with SelectResult.

Throws
ChannelClosedException

When any of the channels is closed (done or in error).

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

Attributes

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

Attributes

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

Attributes

See also
def select[T1, T2, T3, T4, T5](source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4], source5: Source[T5]): T1 | T2 | T3 | T4 | T5

Attributes

See also
def select[T](sources: Seq[Source[T]])(using DummyImplicit): T | ChannelClosed

Select exactly one source, from which to receive a value. Sources should not repeat. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one source, from which to receive a value. Sources should not repeat. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

If a couple of the sources have values which can be received immediately, the select is biased towards the source that appears first.

If no sources are given, returns ChannelClosed.Done.

For a variant which doesn't throw exceptions when any of the channels is closed, use selectOrClosed.

Value parameters

sources

The sources, from which a value will be received.

Attributes

Returns

The value received from the selected source.

Throws
ChannelClosedException

When any of the channels is closed (done or in error).

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

Attributes

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

Attributes

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

Attributes

See also
def selectOrClosed(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_], clause4: SelectClause[_], clause5: SelectClause[_]): clause1.Result | clause2.Result | clause3.Result | clause4.Result | clause5.Result | ChannelClosed

Attributes

See also
def selectOrClosed[T](clauses: Seq[SelectClause[T]]): SelectResult[T] | ChannelClosed

Select exactly one clause to complete. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one clause to complete. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

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, returns ChannelClosed.Done.

For a variant which throws exceptions when any of the channels is closed, use select.

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).

def selectOrClosed[T1, T2](source1: Source[T1], source2: Source[T2]): T1 | T2 | ChannelClosed

Attributes

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

Attributes

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

Attributes

See also
def selectOrClosed[T1, T2, T3, T4, T5](source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4], source5: Source[T5]): T1 | T2 | T3 | T4 | T5 | ChannelClosed

Attributes

See also
def selectOrClosed[T](sources: Seq[Source[T]])(using DummyImplicit): T | ChannelClosed

Select exactly one source, from which to receive a value. Sources should not repeat. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one source, from which to receive a value. Sources should not repeat. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

If a couple of the sources have values which can be received immediately, the select is biased towards the source that appears first.

If no sources are given, returns ChannelClosed.Done.

For a variant which throws exceptions when any of the channels is closed, use select.

Value parameters

sources

The sources, from which a value will be received.

Attributes

Returns

The value received from the selected source, or a ChannelClosed, when any of the channels is closed (done or in error).

def selectOrClosedWithin[TV](timeout: FiniteDuration, timeoutValue: TV)(clause1: SelectClause[_]): TV | clause1.Result | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV](timeout: FiniteDuration, timeoutValue: TV)(clause1: SelectClause[_], clause2: SelectClause[_]): TV | clause1.Result | clause2.Result | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV](timeout: FiniteDuration, timeoutValue: TV)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_]): TV | clause1.Result | clause2.Result | clause3.Result | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV](timeout: FiniteDuration, timeoutValue: TV)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_], clause4: SelectClause[_]): TV | clause1.Result | clause2.Result | clause3.Result | clause4.Result | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV](timeout: FiniteDuration, timeoutValue: TV)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_], clause4: SelectClause[_], clause5: SelectClause[_]): TV | clause1.Result | clause2.Result | clause3.Result | clause4.Result | clause5.Result | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV, T](timeout: FiniteDuration, timeoutValue: TV)(clauses: Seq[SelectClause[T]]): TV | SelectResult[T] | ChannelClosed

Select exactly one clause to complete within the given timeout. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one clause to complete within the given timeout. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

If any clause can be completed immediately, it is selected (no timeout is needed). 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, returns the timeout value immediately.

The implementation creates a buffered channel of size 1, an unsupervised scope, and within that scope starts a fork that sends the timeout value to the channel after the specified timeout duration. The select then chooses from the provided clauses or the timeout channel.

Value parameters

clauses

The clauses, from which one will be selected (or timeout will occur)

timeout

The maximum time to wait for any clause to complete

timeoutValue

The value to return if the timeout is reached before any clause completes

Attributes

Returns

Either the timeout value, the result returned by the selected clause, or a ChannelClosed when any of the channels is closed (done or in error).

def selectOrClosedWithin[TV, T1](timeout: FiniteDuration, timeoutValue: TV)(source1: Source[T1]): TV | T1 | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV, T1, T2](timeout: FiniteDuration, timeoutValue: TV)(source1: Source[T1], source2: Source[T2]): TV | T1 | T2 | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TimeoutValue, T1, T2, T3](timeout: FiniteDuration, timeoutValue: TimeoutValue)(source1: Source[T1], source2: Source[T2], source3: Source[T3]): TimeoutValue | T1 | T2 | T3 | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV, T1, T2, T3, T4](timeout: FiniteDuration, timeoutValue: TV)(source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4]): TV | T1 | T2 | T3 | T4 | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV, T1, T2, T3, T4, T5](timeout: FiniteDuration, timeoutValue: TV)(source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4], source5: Source[T5]): TV | T1 | T2 | T3 | T4 | T5 | ChannelClosed

Attributes

See also
def selectOrClosedWithin[TV, T](timeout: FiniteDuration, timeoutValue: TV)(sources: Seq[Source[T]])(using DummyImplicit): TV | T | ChannelClosed

Select exactly one source from which to receive a value, within the given timeout. Sources should not repeat.

Select exactly one source from which to receive a value, within the given timeout. Sources should not repeat.

If any source has a value that can be received immediately, it is selected (no timeout is needed). If a couple of the sources have values that can be received immediately, the select is biased towards the source that appears first.

If no sources are given, returns the timeout value immediately.

The implementation creates a buffered channel of size 1, an unsupervised scope, and within that scope starts a fork that sends the timeout value to the channel after the specified timeout duration. The select then chooses from the provided sources or the timeout channel.

Value parameters

sources

The sources, from which a value will be received (or timeout will occur)

timeout

The maximum time to wait for any source to have a value available

timeoutValue

The value to return if the timeout is reached before any source has a value available

Attributes

Returns

Either the timeout value, the value received from the selected source, or a ChannelClosed when any of the channels is closed (done or in error).

def selectWithin(timeout: FiniteDuration)(clause1: SelectClause[_]): clause1.Result

Attributes

See also
def selectWithin(timeout: FiniteDuration)(clause1: SelectClause[_], clause2: SelectClause[_]): clause1.Result | clause2.Result

Attributes

See also
def selectWithin(timeout: FiniteDuration)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_]): clause1.Result | clause2.Result | clause3.Result

Attributes

See also
def selectWithin(timeout: FiniteDuration)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_], clause4: SelectClause[_]): clause1.Result | clause2.Result | clause3.Result | clause4.Result

Attributes

See also
def selectWithin(timeout: FiniteDuration)(clause1: SelectClause[_], clause2: SelectClause[_], clause3: SelectClause[_], clause4: SelectClause[_], clause5: SelectClause[_]): clause1.Result | clause2.Result | clause3.Result | clause4.Result | clause5.Result

Attributes

See also
def selectWithin[T](timeout: FiniteDuration)(clauses: Seq[SelectClause[T]]): SelectResult[T]

Select exactly one clause to complete within the given timeout. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

Select exactly one clause to complete within the given timeout. Each clause should be created for a different channel. Clauses can be created using Source.receiveClause, Sink.sendClause and Default.

If any clause can be completed immediately, it is selected (no timeout is needed). 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, throws a TimeoutException immediately.

The implementation delegates to selectOrClosedWithin using a unique private timeout marker value.

Value parameters

clauses

The clauses, from which one will be selected (or timeout will occur)

timeout

The maximum time to wait for any clause to complete

Attributes

Returns

The result returned by the selected clause, wrapped with SelectResult.

Throws
ChannelClosedException

When any of the channels is closed (done or in error).

TimeoutException

When the timeout is reached before any clause completes.

def selectWithin[T1](timeout: FiniteDuration)(source1: Source[T1]): T1

Attributes

See also
def selectWithin[T1, T2](timeout: FiniteDuration)(source1: Source[T1], source2: Source[T2]): T1 | T2

Attributes

See also
def selectWithin[T1, T2, T3](timeout: FiniteDuration)(source1: Source[T1], source2: Source[T2], source3: Source[T3]): T1 | T2 | T3

Attributes

See also
def selectWithin[T1, T2, T3, T4](timeout: FiniteDuration)(source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4]): T1 | T2 | T3 | T4

Attributes

See also
def selectWithin[T1, T2, T3, T4, T5](timeout: FiniteDuration)(source1: Source[T1], source2: Source[T2], source3: Source[T3], source4: Source[T4], source5: Source[T5]): T1 | T2 | T3 | T4 | T5

Attributes

See also
def selectWithin[T](timeout: FiniteDuration)(sources: Seq[Source[T]])(using DummyImplicit): T

Select exactly one source from which to receive a value, within the given timeout. Sources should not repeat.

Select exactly one source from which to receive a value, within the given timeout. Sources should not repeat.

If any source has a value that can be received immediately, it is selected (no timeout is needed). If a couple of the sources have values that can be received immediately, the select is biased towards the source that appears first.

If no sources are given, throws a TimeoutException immediately.

The implementation delegates to selectOrClosedWithin using a unique private timeout marker value.

Value parameters

sources

The sources, from which a value will be received (or timeout will occur)

timeout

The maximum time to wait for any source to have a value available

Attributes

Returns

The value received from the selected source.

Throws
ChannelClosedException

When any of the channels is closed (done or in error).

TimeoutException

When the timeout is reached before any source has a value available.

Extensions

Extensions

extension (c: BufferCapacity)
def toInt: Int