Various operations which allow creating Source instances.
Some need to be run within a concurrency scope, such as supervised.
Attributes
Members list
Value members
Inherited methods
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
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
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
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
Creates a source that emits elements from future source when from
completes or fails otherwise. The from
completion is performed on the provided scala.concurrent.ExecutionContext whereas elements are emitted through Ox. Note that when from
fails with scala.concurrent.ExecutionException then its cause is returned as source failure.
Creates a source that emits elements from future source when from
completes or fails otherwise. The from
completion is performed on the provided scala.concurrent.ExecutionContext whereas elements are emitted through Ox. 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
Sends a given number of elements (determined byc segmentSize
) from each source in sources
to the returned channel and repeats. The order of elements in all sources is preserved.
Sends a given number of elements (determined byc segmentSize
) from each source in sources
to the returned channel and repeats. The order of elements in all sources is preserved.
If any of the sources is done before the others, the behavior depends on the eagerCancel
flag. When set to true
, the returned channel is completed immediately, otherwise the interleaving continues with the remaining non-completed sources. Once all but one sources are complete, the elements of the remaining non-complete source are sent to the returned channel.
Must be run within a scope, since a child fork is created which receives from the subsequent sources and sends to the resulting channel.
Value parameters
- eagerComplete
-
If
true
, the returned channel is completed as soon as any of the sources completes. If 'false`, the interleaving continues with the remaining non-completed sources. - segmentSize
-
The number of elements sent from each source before switching to the next one. Default is 1.
- sources
-
The sources whose elements will be interleaved.
Attributes
- Returns
-
A source to which the interleaved elements from both sources would be sent.
- Example
-
scala> import ox.* import ox.channels.Source supervised { val s1 = Source.fromValues(1, 2, 3, 4, 5, 6, 7, 8) val s2 = Source.fromValues(10, 20, 30) val s3 = Source.fromValues(100, 200, 300, 400, 500) Source.interleaveAll(List(s1, s2, s3), segmentSize = 2, eagerComplete = true).toList } scala> val res0: List[Int] = List(1, 2, 10, 20, 100, 200, 3, 4, 30)
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
A range of number, from from
, to to
(inclusive), stepped by step
.
A range of number, from from
, to to
(inclusive), stepped by step
.
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps