Source

ox.channels.Source
See theSource companion trait
object Source extends SourceCompanionOps

Various operations which allow creating Source instances.

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

Attributes

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

Members list

Value members

Inherited methods

def empty[T]: Source[T]

Creates an empty source, that is immediately completed as done.

Creates an empty source, that is immediately completed as done.

Attributes

Inherited from:
SourceCompanionOps
def failed[T](t: Throwable): Source[T]

Creates a source that fails immediately with the given java.lang.Throwable

Creates a source that fails immediately with the given java.lang.Throwable

Value parameters

t

The java.lang.Throwable to fail with

Attributes

Returns

A source that would fail immediately with the given java.lang.Throwable

Inherited from:
SourceCompanionOps
def fromFork[T](f: Fork[T])(using Ox, BufferCapacity): Source[T]

Attributes

Inherited from:
SourceCompanionOps
def fromFuture[T](from: Future[T])(using BufferCapacity, ExecutionContext): Source[T]

Creates a source that emits a single value when from completes or fails otherwise. The from completion is performed on the provided scala.concurrent.ExecutionContext. Note that when from fails with scala.concurrent.ExecutionException then its cause is returned as source failure.

Creates a source that emits a single value when from completes or fails otherwise. The from completion is performed on the provided scala.concurrent.ExecutionContext. Note that when from fails with scala.concurrent.ExecutionException then its cause is returned as source failure.

Value parameters

from

A scala.concurrent.Future that returns value upon completion.

Attributes

Returns

A source that will emit value upon a from scala.concurrent.Future completion.

Example
 import ox.*
 import ox.channels.Source
 import scala.concurrent.ExecutionContext.Implicits.global
 import scala.concurrent.Future
 supervised {
   Source
     .future(Future.failed(new RuntimeException("future failed")))
     .receive()                               // ChannelClosed.Error(java.lang.RuntimeException: future failed)
   Source.future(Future.successful(1)).toList // List(1)
 }
Inherited from:
SourceCompanionOps
def fromFutureSource[T](from: Future[Source[T]])(using Ox, BufferCapacity, ExecutionContext): Source[T]

Creates a source to which the future's value is sent, once from completes or fails otherwise. The from completion is performed on the provided scala.concurrent.ExecutionContext. Note that when from fails with scala.concurrent.ExecutionException then its cause is returned as source failure.

Creates a source to which the future's value is sent, once from completes or fails otherwise. The from completion is performed on the provided scala.concurrent.ExecutionContext. Note that when from fails with scala.concurrent.ExecutionException then its cause is returned as source failure.

Value parameters

from

A scala.concurrent.Future that returns source upon completion.

Attributes

Returns

A source that will emit values upon a from scala.concurrent.Future completion.

Example
 import ox.*
 import ox.channels.Source
 import scala.concurrent.ExecutionContext.Implicits.global
 import scala.concurrent.Future
 supervised {
   Source
     .futureSource(Future.failed(new RuntimeException("future failed")))
     .receive()                                                           // ChannelClosed.Error(java.lang.RuntimeException: future failed)
   Source.futureSource(Future.successful(Source.fromValues(1, 2))).toList // List(1, 2)
 }
Inherited from:
SourceCompanionOps
def fromIterable[T](it: Iterable[T])(using Ox, BufferCapacity): Source[T]

Attributes

Inherited from:
SourceCompanionOps
def fromIterator[T](it: => Iterator[T])(using Ox, BufferCapacity): Source[T]

Attributes

Inherited from:
SourceCompanionOps
def fromValues[T](ts: T*)(using Ox, BufferCapacity): Source[T]

Attributes

Inherited from:
SourceCompanionOps