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
Creates a channel, to which the given element
is sent repeatedly.
Creates a channel, to which the given element
is sent repeatedly.
Value parameters
- element
-
The element to send
Attributes
- Returns
-
A source to which the given element is sent repeatedly.
- Inherited from:
- SourceCompanionOps
Creates a channel, to which the result of evaluating f
is sent repeatedly. As the parameter is passed by-name, the evaluation is deferred until the element is sent, and happens multiple times.
Creates a channel, to which the result of evaluating f
is sent repeatedly. As the parameter is passed by-name, the evaluation is deferred until the element is sent, and happens multiple times.
Value parameters
- f
-
The code block, computing the element to send
Attributes
- Returns
-
A source to which the result of evaluating
f
is sent repeatedly. - Inherited from:
- SourceCompanionOps
Creates a rendezvous channel (without a buffer, regardless of the StageCapacity in scope), to which the given value is sent repeatedly, at least interval apart between each two elements. The first value is sent immediately.
Creates a rendezvous channel (without a buffer, regardless of the StageCapacity in scope), to which the given value is sent repeatedly, at least interval apart between each two elements. The first value is sent immediately.
The interval is measured between the subsequent invocations of the send(value)
method. Hence, if there's a slow consumer, the next tick can be sent right after the previous one is received (if it was received later than the inter-tick interval duration). However, ticks don't accumulate, e.g. when the consumer is so slow that multiple intervals pass between send
invocations.
Must be run within a scope, since a child fork is created which sends the ticks, and waits until the next tick can be sent.
Value parameters
- interval
-
The temporal spacing between subsequent ticks.
- value
-
The value to send to the channel on every tick.
Attributes
- Returns
-
A source to which the tick values are sent.
- Example
-
scala> import ox.* import ox.channels.Source import scala.concurrent.duration.DurationInt supervised { val s1 = Source.tick(100.millis) s1.receive() s2.receive() // this will complete at least 100 milliseconds later }
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps
Attributes
- Inherited from:
- SourceCompanionOps