Class Source
TBD
Inherited Members
Namespace: Akka.Streams.Dsl
Assembly: Akka.Streams.dll
Syntax
public static class Source
Methods
| Improve this Doc View SourceActorPublisher<T>(Props)
Creates a Source<TOut, TMat> that is materialized to an IActorRef which points to an Actor created according to the passed in Props. Actor created by the Props must be ActorPublisher<T>.
Declaration
public static Source<T, IActorRef> ActorPublisher<T>(Props props)
Parameters
Type | Name | Description |
---|---|---|
Props | props | TBD |
Returns
Type | Description |
---|---|
Source<T, IActorRef> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | This exception is thrown when the specified actor |
ActorRef<T>(Int32, OverflowStrategy)
Creates a Source<TOut, TMat> that is materialized as an IActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.
Depending on the defined OverflowStrategy it might drop elements if there is no space available in the buffer.
The strategy Backpressure is not supported, and an IllegalArgument("Backpressure overflowStrategy not supported") will be thrown if it is passed as argument.
The buffer can be disabled by using bufferSize
of 0 and then received messages are dropped
if there is no demand from downstream. When bufferSize
is 0 the overflowStrategy
does
not matter. An async boundary is added after this Source; as such, it is never safe to assume the downstream will always generate demand.
The stream can be completed successfully by sending the actor reference a Status.Success message (whose content will be ignored) in which case already buffered elements will be signaled before signaling completion, or by sending PoisonPill in which case completion will be signaled immediately.
The stream can be completed with failure by sending a Status.Failure to the actor reference. In case the Actor is still draining its internal buffer (after having received a Status.Success) before signaling completion and it receives a Status.Failure, the failure will be signaled downstream immediately (instead of the completion signal).
Note that terminating the actor without first completing it, either with a success or a failure, will prevent the actor triggering downstream completion and the stream will continue to run even though the source actor is dead. Therefore you should not attempt to manually terminate the actor such as with a PoisonPill.
The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
See also Queue<T>(Int32, OverflowStrategy)Declaration
public static Source<T, IActorRef> ActorRef<T>(int bufferSize, OverflowStrategy overflowStrategy)
Parameters
Type | Name | Description |
---|---|---|
Int32 | bufferSize | The size of the buffer in element count |
OverflowStrategy | overflowStrategy | Strategy that is used when incoming elements cannot fit inside the buffer |
Returns
Type | Description |
---|---|
Source<T, IActorRef> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | This exception is thrown when the specified |
NotSupportedException | This exception is thrown when the specified |
AsSubscriber<T>()
Creates a Source<TOut, TMat> that is materialized as a Reactive.Streams.ISubscriber<T>
Declaration
public static Source<T, ISubscriber<T>> AsSubscriber<T>()
Returns
Type | Description |
---|---|
Source<T, Reactive.Streams.ISubscriber<T>> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Channel<T>(Int32, Boolean, BoundedChannelFullMode)
Creates a Source that materializes a System.Threading.Channels.ChannelWriter<T> that may be used to write items to the stream.
This works similarly to Queue<T>(Int32, OverflowStrategy), The main difference being that you are allowed to have multiple Writes in flight. Allowing multiple writes makes Multi-producer scenarios easier but is still an important semantic difference.
Declaration
public static Source<T, ChannelWriter<T>> Channel<T>(int bufferSize, bool singleWriter = false, BoundedChannelFullMode fullMode = BoundedChannelFullMode.Wait)
Parameters
Type | Name | Description |
---|---|---|
Int32 | bufferSize | The size of the channel's buffer |
Boolean | singleWriter | If true, expects only one writer |
System.Threading.Channels.BoundedChannelFullMode | fullMode | How the channel behaves when full |
Returns
Type | Description |
---|---|
Source<T, System.Threading.Channels.ChannelWriter<T>> |
Type Parameters
Name | Description |
---|---|
T |
ChannelReader<T>(ChannelReader<T>)
Declaration
public static Source<T, NotUsed> ChannelReader<T>(ChannelReader<T> channelReader)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.Channels.ChannelReader<T> | channelReader |
Returns
Type | Description |
---|---|
Source<T, NotUsed> |
Type Parameters
Name | Description |
---|---|
T |
Combine<T, TOut2>(Source<T, NotUsed>, Source<T, NotUsed>, Func<Int32, IGraph<UniformFanInShape<T, TOut2>, NotUsed>>, Source<T, NotUsed>[])
Combines several sources with fun-in strategy like Merge<TIn, TOut> or Concat<TIn, TOut> and returns Source<TOut, TMat>.
Declaration
public static Source<TOut2, NotUsed> Combine<T, TOut2>(Source<T, NotUsed> first, Source<T, NotUsed> second, Func<int, IGraph<UniformFanInShape<T, TOut2>, NotUsed>> strategy, params Source<T, NotUsed>[] rest)
Parameters
Type | Name | Description |
---|---|---|
Source<T, NotUsed> | first | TBD |
Source<T, NotUsed> | second | TBD |
Func<Int32, IGraph<UniformFanInShape<T, TOut2>, NotUsed>> | strategy | TBD |
Source<T, NotUsed>[] | rest | TBD |
Returns
Type | Description |
---|---|
Source<TOut2, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TOut2 | TBD |
CombineMaterialized<T, TOut2, TMat1, TMat2, TMatOut>(Source<T, TMat1>, Source<T, TMat2>, Func<Int32, IGraph<UniformFanInShape<T, TOut2>, NotUsed>>, Func<TMat1, TMat2, TMatOut>)
Combines two sources with fan-in strategy like Merge<TIn, TOut> or Concat<TIn, TOut> and returns Source<TOut, TMat> with a materialized value.
Declaration
public static Source<TOut2, TMatOut> CombineMaterialized<T, TOut2, TMat1, TMat2, TMatOut>(Source<T, TMat1> first, Source<T, TMat2> second, Func<int, IGraph<UniformFanInShape<T, TOut2>, NotUsed>> strategy, Func<TMat1, TMat2, TMatOut> combineMaterializers)
Parameters
Type | Name | Description |
---|---|---|
Source<T, TMat1> | first | TBD |
Source<T, TMat2> | second | TBD |
Func<Int32, IGraph<UniformFanInShape<T, TOut2>, NotUsed>> | strategy | TBD |
Func<TMat1, TMat2, TMatOut> | combineMaterializers | TBD |
Returns
Type | Description |
---|---|
Source<TOut2, TMatOut> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TOut2 | TBD |
TMat1 | TBD |
TMat2 | TBD |
TMatOut | TBD |
Cycle<T>(Func<IEnumerator<T>>)
Create Source<TOut, TMat> that will continually produce given elements in specified order. Start a new cycled Source<TOut, TMat> from the given elements. The producer stream of elements will continue infinitely by repeating the sequence of elements provided by function parameter.
Declaration
public static Source<T, NotUsed> Cycle<T>(Func<IEnumerator<T>> enumeratorFactory)
Parameters
Type | Name | Description |
---|---|---|
Func<IEnumerator<T>> | enumeratorFactory | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Empty<T>()
A Source<TOut, TMat> with no elements, i.e. an empty stream that is completed immediately for every connected Sink<TIn, TMat>.
Declaration
public static Source<T, NotUsed> Empty<T>()
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Failed<T>(Exception)
Create a Source<TOut, TMat> that immediately ends the stream with the cause
error to every connected Sink<TIn, TMat>.
Declaration
public static Source<T, NotUsed> Failed<T>(Exception cause)
Parameters
Type | Name | Description |
---|---|---|
Exception | cause | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
From<T>(IEnumerable<T>)
Helper to create Source<TOut, TMat> from IEnumerable<T>. Example usage: Source.From(Enumerable.Range(1, 10))
Starts a new Source<TOut, TMat> from the given IEnumerable<T>. This is like starting from an Enumerator, but every Subscriber directly attached to the Publisher of this stream will see an individual flow of elements (always starting from the beginning) regardless of when they subscribed.
Declaration
public static Source<T, NotUsed> From<T>(IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
From<T>(Func<IAsyncEnumerable<T>>)
Helper to create Source<TOut, TMat> from System.Collections.Generic.IAsyncEnumerable<T>. Example usage: Source.From(Enumerable.Range(1, 10))
Starts a new Source<TOut, TMat> from the given System.Collections.Generic.IAsyncEnumerable<T>. This is like starting from an Enumerator, but every Subscriber directly attached to the Publisher of this stream will see an individual flow of elements (always starting from the beginning) regardless of when they subscribed.
Declaration
public static Source<T, NotUsed> From<T>(Func<IAsyncEnumerable<T>> asyncEnumerable)
Parameters
Type | Name | Description |
---|---|---|
Func<System.Collections.Generic.IAsyncEnumerable<T>> | asyncEnumerable |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
FromEnumerator<T>(Func<IEnumerator<T>>)
Helper to create Source<TOut, TMat> from IEnumerator<T>. Example usage: Source.FromEnumerator(() => Enumerable.Range(1, 10))
Start a new Source<TOut, TMat> from the given function that produces an IEnumerable<T>. The produced stream of elements will continue until the enumerator runs empty or fails during evaluation of the IEnumerator<T>.MoveNext method. Elements are pulled out of the enumerator in accordance with the demand coming from the downstream transformation steps.
Declaration
public static Source<T, NotUsed> FromEnumerator<T>(Func<IEnumerator<T>> enumeratorFactory)
Parameters
Type | Name | Description |
---|---|---|
Func<IEnumerator<T>> | enumeratorFactory | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
FromEvent<T>(Action<EventHandler<T>>, Action<EventHandler<T>>, Int32, OverflowStrategy)
Start a new Source<TOut, TMat> attached to a .NET event. In case when event will be triggered faster, than a downstream is able
to consume incoming events, a buffering will occur. It can be configured via optional maxBufferCapacity
and
overflowStrategy
parameters.
Declaration
public static Source<T, NotUsed> FromEvent<T>(Action<EventHandler<T>> addHandler, Action<EventHandler<T>> removeHandler, int maxBufferCapacity = 128, OverflowStrategy overflowStrategy = OverflowStrategy.DropHead)
Parameters
Type | Name | Description |
---|---|---|
Action<EventHandler<T>> | addHandler | Action used to attach the given event handler to the underlying .NET event. |
Action<EventHandler<T>> | removeHandler | Action used to detach the given event handler to the underlying .NET event. |
Int32 | maxBufferCapacity | Maximum size of the buffer, used in situation when amount of emitted events is higher than current processing capabilities of the downstream. |
OverflowStrategy | overflowStrategy | Overflow strategy used, when buffer (size specified by |
Returns
Type | Description |
---|---|
Source<T, NotUsed> |
Type Parameters
Name | Description |
---|---|
T | Type of the event args produced as source events. |
FromEvent<TDelegate, T>(Func<Action<T>, TDelegate>, Action<TDelegate>, Action<TDelegate>, Int32, OverflowStrategy)
Start a new Source<TOut, TMat> attached to a .NET event. In case when event will be triggered faster, than a downstream is able
to consume incoming events, a buffering will occur. It can be configured via optional maxBufferCapacity
and
overflowStrategy
parameters.
Declaration
public static Source<T, NotUsed> FromEvent<TDelegate, T>(Func<Action<T>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler, int maxBufferCapacity = 128, OverflowStrategy overflowStrategy = OverflowStrategy.DropHead)
Parameters
Type | Name | Description |
---|---|---|
Func<Action<T>, TDelegate> | conversion | A function used to convert provided event handler into a delegate compatible with an underlying .NET event type. |
Action<TDelegate> | addHandler | Action used to attach the given event handler to the underlying .NET event. |
Action<TDelegate> | removeHandler | Action used to detach the given event handler to the underlying .NET event. |
Int32 | maxBufferCapacity | Maximum size of the buffer, used in situation when amount of emitted events is higher than current processing capabilities of the downstream. |
OverflowStrategy | overflowStrategy | Overflow strategy used, when buffer (size specified by |
Returns
Type | Description |
---|---|
Source<T, NotUsed> |
Type Parameters
Name | Description |
---|---|
TDelegate | Delegate type used to attach current source. |
T | Type of the event args produced as source events. |
FromGraph<T, TMat>(IGraph<SourceShape<T>, TMat>)
A graph with the shape of a source logically is a source, this method makes it so also in type.
Declaration
public static Source<T, TMat> FromGraph<T, TMat>(IGraph<SourceShape<T>, TMat> source)
Parameters
Type | Name | Description |
---|---|---|
IGraph<SourceShape<T>, TMat> | source | TBD |
Returns
Type | Description |
---|---|
Source<T, TMat> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TMat | TBD |
FromObservable<T>(IObservable<T>, Int32, OverflowStrategy)
Start a new Source<TOut, TMat> attached to an existing IObservable<T>. In case when upstream (an observable
)
is producing events in a faster pace, than downstream is able to consume them, a buffering will occur. It can be configured via optional
maxBufferCapacity
and overflowStrategy
parameters.
Declaration
public static Source<T, NotUsed> FromObservable<T>(IObservable<T> observable, int maxBufferCapacity = 128, OverflowStrategy overflowStrategy = OverflowStrategy.DropHead)
Parameters
Type | Name | Description |
---|---|---|
IObservable<T> | observable | An IObservable<T> to which current source will be subscribed. |
Int32 | maxBufferCapacity | Maximum size of the buffer, used in situation when amount of emitted events is higher than current processing capabilities of the downstream. |
OverflowStrategy | overflowStrategy | Overflow strategy used, when buffer (size specified by |
Returns
Type | Description |
---|---|
Source<T, NotUsed> |
Type Parameters
Name | Description |
---|---|
T | Type of the event args produced as source events. |
FromPublisher<T>(IPublisher<T>)
Helper to create Source<TOut, TMat> from Reactive.Streams.IPublisher<T>.
Construct a transformation starting with given publisher. The transformation steps are executed by a series of Reactive.Streams.IProcessor`2 instances that mediate the flow of elements downstream and the propagation of back-pressure upstream.
Declaration
public static Source<T, NotUsed> FromPublisher<T>(IPublisher<T> publisher)
Parameters
Type | Name | Description |
---|---|---|
Reactive.Streams.IPublisher<T> | publisher | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
FromTask<T>(Task<T>)
Start a new Source<TOut, TMat> from the given Task<TResult>. The stream will consist of one element when the Task<TResult> is completed with a successful value, which may happen before or after materializing the IFlow<TOut, TMat>. The stream terminates with a failure if the task is completed with a failure.
Declaration
public static Source<T, NotUsed> FromTask<T>(Task<T> task)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
FromTaskSource<T, M>(Task<Source<T, M>>)
Streams the elements of the given future source once it successfully completes. If the Task<TResult> fails the stream is failed with the exception from the future. If downstream cancels before the stream completes the materialized Task<TResult> will be failed with a StreamDetachedException
Declaration
public static Source<T, Task<M>> FromTaskSource<T, M>(Task<Source<T, M>> task)
Parameters
Type | Name | Description |
---|---|---|
Task<Source<T, M>> | task | TBD |
Returns
Type | Description |
---|---|
Source<T, Task<M>> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
M | TBD |
Lazily<TOut, TMat>(Func<Source<TOut, TMat>>)
Creates a Source<TOut, TMat> that is not materialized until there is downstream demand, when the source gets materialized
the materialized task is completed with its value, if downstream cancels or fails without any demand the
create
factory is never called and the materialized Task<TResult> is failed.
Declaration
public static Source<TOut, Task<TMat>> Lazily<TOut, TMat>(Func<Source<TOut, TMat>> create)
Parameters
Type | Name | Description |
---|---|---|
Func<Source<TOut, TMat>> | create |
Returns
Type | Description |
---|---|
Source<TOut, Task<TMat>> |
Type Parameters
Name | Description |
---|---|
TOut | |
TMat |
Maybe<T>()
Create a Source<TOut, TMat> which materializes a TaskCompletionSource<TResult> which controls what element will be emitted by the Source. If the materialized promise is completed with a Some, that value will be produced downstream, followed by completion. If the materialized promise is completed with a None, no value will be produced downstream and completion will be signaled immediately. If the materialized promise is completed with a failure, then the returned source will terminate with that error. If the downstream of this source cancels before the promise has been completed, then the promise will be completed with None.
Declaration
public static Source<T, TaskCompletionSource<T>> Maybe<T>()
Returns
Type | Description |
---|---|
Source<T, TaskCompletionSource<T>> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Never<T>()
Never emits any elements, never completes and never fails. This stream could be useful in tests.
Declaration
public static Source<T, NotUsed> Never<T>()
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Queue<T>(Int32, OverflowStrategy)
Creates a Source<TOut, TMat> that is materialized as an ISourceQueueWithComplete<T>. You can push elements to the queue and they will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.
Depending on the defined OverflowStrategy it might drop elements if there is no space available in the buffer.
Acknowledgement mechanism is available. ISourceQueueWithComplete<T>.OfferAsync returns Task which completes with QueueOfferResult.Enqueued if element was added to buffer or sent downstream. It completes with QueueOfferResult.Dropped if element was dropped. Can also complete with QueueOfferResult.Failure - when stream failed or QueueOfferResult.QueueClosed when downstream is completed.
The strategy Backpressure will not complete ISourceQueueWithComplete<T>.OfferAsync when buffer is full.
The buffer can be disabled by using bufferSize
of 0 and then received messages will wait
for downstream demand unless there is another message waiting for downstream demand, in that case
offer result will be completed according to the overflowStrategy
.
Declaration
public static Source<T, ISourceQueueWithComplete<T>> Queue<T>(int bufferSize, OverflowStrategy overflowStrategy)
Parameters
Type | Name | Description |
---|---|---|
Int32 | bufferSize | The size of the buffer in element count |
OverflowStrategy | overflowStrategy | Strategy that is used when incoming elements cannot fit inside the buffer |
Returns
Type | Description |
---|---|
Source<T, ISourceQueueWithComplete<T>> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | This exception is thrown when the specified |
Repeat<T>(T)
Create a Source<TOut, TMat> that will continually emit the given element.
Declaration
public static Source<T, NotUsed> Repeat<T>(T element)
Parameters
Type | Name | Description |
---|---|---|
T | element | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Setup<T, TMat>(Func<ActorMaterializer, Attributes, Source<T, TMat>>)
Defers the creation of a Source until materialization. The factory
function exposes ActorMaterializer which is going to be used during materialization and
Attributes of the Source returned by this method.
Declaration
public static Source<T, Task<TMat>> Setup<T, TMat>(Func<ActorMaterializer, Attributes, Source<T, TMat>> factory)
Parameters
Type | Name | Description |
---|---|---|
Func<ActorMaterializer, Attributes, Source<T, TMat>> | factory | TBD |
Returns
Type | Description |
---|---|
Source<T, Task<TMat>> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TMat | TBD |
Shape<T>(String)
TBD
Declaration
public static SourceShape<T> Shape<T>(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | TBD |
Returns
Type | Description |
---|---|
SourceShape<T> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Single<T>(T)
Create a Source<TOut, TMat> with one element. Every connected Sink<TIn, TMat> of this stream will see an individual stream consisting of one element.
Declaration
public static Source<T, NotUsed> Single<T>(T element)
Parameters
Type | Name | Description |
---|---|---|
T | element | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Tick<T>(TimeSpan, TimeSpan, T)
Elements are emitted periodically with the specified interval. The tick element will be delivered to downstream consumers that has requested any elements. If a consumer has not requested any elements at the point in time when the tick element is produced it will not receive that tick element later. It will receive new tick elements as soon as it has requested more elements.
Declaration
public static Source<T, ICancelable> Tick<T>(TimeSpan initialDelay, TimeSpan interval, T tick)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | initialDelay | TBD |
TimeSpan | interval | TBD |
T | tick | TBD |
Returns
Type | Description |
---|---|
Source<T, ICancelable> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
Unfold<TState, TElem>(TState, Func<TState, Option<(TState, TElem)>>)
Create a Source<TOut, TMat> that will unfold a value of type TState
into
a pair of the next state TState
and output elements of type TElem
.
Declaration
public static Source<TElem, NotUsed> Unfold<TState, TElem>(TState state, Func<TState, Option<(TState, TElem)>> unfold)
Parameters
Type | Name | Description |
---|---|---|
TState | state | TBD |
Func<TState, Option<System.ValueTuple<TState, TElem>>> | unfold | TBD |
Returns
Type | Description |
---|---|
Source<TElem, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
TState | TBD |
TElem | TBD |
Examples
For example, all the Fibonacci numbers under 10M:
Source.unfold(0 → 1) {
case (a, _) if a > 10000000 ⇒ None
case (a, b) ⇒ Some((b → (a + b)) → a)
}
|
Improve this Doc
View Source
UnfoldAsync<TState, TElem>(TState, Func<TState, Task<Option<(TState, TElem)>>>)
Same as Unfold<TState, TElem>(TState, Func<TState, Option<(TState, TElem)>>), but uses an async function to generate the next state-element tuple.
Declaration
public static Source<TElem, NotUsed> UnfoldAsync<TState, TElem>(TState state, Func<TState, Task<Option<(TState, TElem)>>> unfoldAsync)
Parameters
Type | Name | Description |
---|---|---|
TState | state | TBD |
Func<TState, Task<Option<System.ValueTuple<TState, TElem>>>> | unfoldAsync | TBD |
Returns
Type | Description |
---|---|
Source<TElem, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
TState | TBD |
TElem | TBD |
Examples
For example, all the Fibonacci numbers under 10M:
Source.unfoldAsync(0 → 1) {
case (a, _) if a > 10000000 ⇒ Future.successful(None)
case (a, b) ⇒ Future{
Thread.sleep(1000)
Some((b → (a + b)) → a)
}
}
|
Improve this Doc
View Source
UnfoldInfinite<TState, TElem>(TState, Func<TState, (TState, TElem)>)
Simpler Unfold<TState, TElem>(TState, Func<TState, Option<(TState, TElem)>>), for infinite sequences.
Declaration
public static Source<TElem, NotUsed> UnfoldInfinite<TState, TElem>(TState state, Func<TState, (TState, TElem)> unfold)
Parameters
Type | Name | Description |
---|---|---|
TState | state | TBD |
Func<TState, System.ValueTuple<TState, TElem>> | unfold | TBD |
Returns
Type | Description |
---|---|
Source<TElem, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
TState | TBD |
TElem | TBD |
Examples
{{{
Source.unfoldInf(0 → 1) {
case (a, b) ⇒ (b → (a + b)) → a
}
}}}
|
Improve this Doc
View Source
UnfoldResource<T, TSource>(Func<TSource>, Func<TSource, Option<T>>, Action<TSource>)
Start a new Source<TOut, TMat> from some resource which can be opened, read and closed. Interaction with resource happens in a blocking way.
Example: {{{ Source.unfoldResource( () => new BufferedReader(new FileReader("...")), reader => Option(reader.readLine()), reader => reader.close()) }}}
You can use the supervision strategy to handle exceptions for read
function. All exceptions thrown by create
or close
will fail the stream.
Restart supervision strategy will close and create blocking IO again. Default strategy is Stop which means
that stream will be terminated on error in read
function by default.
You can configure the default dispatcher for this Source by changing the akka.stream.blocking-io-dispatcher
or
set it for a given Source by using CreateDispatcher(String).
Adheres to the ActorAttributes.SupervisionStrategy attribute.
Declaration
public static Source<T, NotUsed> UnfoldResource<T, TSource>(Func<TSource> create, Func<TSource, Option<T>> read, Action<TSource> close)
Parameters
Type | Name | Description |
---|---|---|
Func<TSource> | create | function that is called on stream start and creates/opens resource. |
Func<TSource, Option<T>> | read | function that reads data from opened resource. It is called each time backpressure signal
is received. Stream calls close and completes when |
Action<TSource> | close | TBD |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TSource | TBD |
UnfoldResourceAsync<T, TSource>(Func<Task<TSource>>, Func<TSource, Task<Option<T>>>, Func<TSource, Task<Done>>)
Start a new Source<TOut, TMat> from some resource which can be opened, read and closed. It's similar to UnfoldResource<T, TSource>(Func<TSource>, Func<TSource, Option<T>>, Action<TSource>) but takes functions that return Tasks instead of plain values.
You can use the supervision strategy to handle exceptions for read
function or failures of produced Tasks.
All exceptions thrown by create
or close
as well as fails of returned futures will fail the stream.
Restart supervision strategy will close and create resource .Default strategy is Stop which means
that stream will be terminated on error in read
function (or task) by default.
You can configure the default dispatcher for this Source by changing the akka.stream.blocking-io-dispatcher
or
set it for a given Source by using CreateDispatcher(String).
Adheres to the ActorAttributes.SupervisionStrategy attribute.
Declaration
public static Source<T, NotUsed> UnfoldResourceAsync<T, TSource>(Func<Task<TSource>> create, Func<TSource, Task<Option<T>>> read, Func<TSource, Task<Done>> close)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<TSource>> | create | function that is called on stream start and creates/opens resource. |
Func<TSource, Task<Option<T>>> | read | function that reads data from opened resource. It is called each time backpressure signal is received. Stream calls close and completes when Task from read function returns None. |
Func<TSource, Task<Done>> | close | function that closes resource |
Returns
Type | Description |
---|---|
Source<T, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TSource | TBD |
ZipN<T>(IEnumerable<Source<T, NotUsed>>)
Combines the elements of multiple streams into a stream of lists.
Declaration
public static Source<IImmutableList<T>, NotUsed> ZipN<T>(IEnumerable<Source<T, NotUsed>> sources)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Source<T, NotUsed>> | sources | TBD |
Returns
Type | Description |
---|---|
Source<System.Collections.Immutable.IImmutableList<T>, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
ZipWithN<T, TOut2>(Func<IImmutableList<T>, TOut2>, IEnumerable<Source<T, NotUsed>>)
Combines the elements of multiple streams into a stream of sequences using a combiner function.
Declaration
public static Source<TOut2, NotUsed> ZipWithN<T, TOut2>(Func<IImmutableList<T>, TOut2> zipper, IEnumerable<Source<T, NotUsed>> sources)
Parameters
Type | Name | Description |
---|---|---|
Func<System.Collections.Immutable.IImmutableList<T>, TOut2> | zipper | TBD |
IEnumerable<Source<T, NotUsed>> | sources | TBD |
Returns
Type | Description |
---|---|
Source<TOut2, NotUsed> | TBD |
Type Parameters
Name | Description |
---|---|
T | TBD |
TOut2 | TBD |