SourceCompanionOps

ox.channels.SourceCompanionOps

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Source

Members list

Value members

Concrete 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

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

def fromFork[T](f: Fork[T])(using Ox, BufferCapacity): Source[T]
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)
 }
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)
 }
def fromIterable[T](it: Iterable[T])(using Ox, BufferCapacity): Source[T]
def fromIterator[T](it: => Iterator[T])(using Ox, BufferCapacity): Source[T]
def fromValues[T](ts: T*)(using Ox, BufferCapacity): Source[T]