Method MapAsync
MapAsync<TInput, TResult>(Stream<TInput>, StreamSink<TResult>, StreamSink<Exception>, MapAsyncOperation<TInput, TResult>, AsyncConcurrencyStrategyBase<Unit>, Stream<Unit>?, Stream<IReadOnlyCollection<TInput>>?, bool)
For a strategy that uses only the schedule and does not read
TInput. Those strategies are Parallel, Queue, and
SwitchLatest.
This overload changes each input to Unit before the
strategy, thus it needs no converter. See the canonical
MapAsync<TInput, TResult, TStrategyInput>(Stream<TInput>, StreamSink<TResult>, StreamSink<Exception>, MapAsyncOperation<TInput, TResult>, AsyncConcurrencyStrategyBase<TStrategyInput>, Func<TInput, TStrategyInput>, Stream<Unit>?, Stream<IReadOnlyCollection<TInput>>?, bool)
overload for the full parameter contract.
public static AsyncMapStatus<TInput, TResult> MapAsync<TInput, TResult>(this Stream<TInput> source, StreamSink<TResult> results, StreamSink<Exception> errors, MapAsyncOperation<TInput, TResult> operation, AsyncConcurrencyStrategyBase<Unit> strategy, Stream<Unit>? cancelAll = null, Stream<IReadOnlyCollection<TInput>>? cancelMatching = null, bool cancelOnDispose = true)
Parameters
sourceStream<TInput>The stream of inputs.
resultsStreamSink<TResult>The destination of the value of each run that succeeded, in the sequence of their ends.
errorsStreamSink<Exception>The destination of the exception of each run with an error.
operationMapAsyncOperation<TInput, TResult>The asynchronous work for each input.
strategyAsyncConcurrencyStrategyBase<Unit>The control of operations that overlap.
cancelAllStream<Unit>This is optional. Each send cancels each tracked operation.
cancelMatchingStream<IReadOnlyCollection<TInput>>This is optional. Each send cancels the tracked operations with a given input value.
cancelOnDisposeboolTrue when a disposal also cancels the tracked items. The default is true.
Returns
- AsyncMapStatus<TInput, TResult>
An AsyncMapStatus<TInput, TResult> that gives the Queued items, the Running items, and Execute. A disposal of it stops the pipeline.
Type Parameters
TInputThe type in the source stream.
TResultThe type that
operationgives when it succeeds.
Exceptions
- ArgumentNullException
source,results,errors,operation, orstrategyis null.
MapAsync<TInput, TResult, TStrategyInput>(Stream<TInput>, StreamSink<TResult>, StreamSink<Exception>, MapAsyncOperation<TInput, TResult>, AsyncConcurrencyStrategyBase<TStrategyInput>, Stream<Unit>?, Stream<IReadOnlyCollection<TInput>>?, bool)
For a strategy that reads the input. Here TInput is
the TStrategyInput of the strategy or a subtype of
it, thus this overload needs no converter. See the canonical
MapAsync<TInput, TResult, TStrategyInput>(Stream<TInput>, StreamSink<TResult>, StreamSink<Exception>, MapAsyncOperation<TInput, TResult>, AsyncConcurrencyStrategyBase<TStrategyInput>, Func<TInput, TStrategyInput>, Stream<Unit>?, Stream<IReadOnlyCollection<TInput>>?, bool)
overload for the full parameter contract.
public static AsyncMapStatus<TInput, TResult> MapAsync<TInput, TResult, TStrategyInput>(this Stream<TInput> source, StreamSink<TResult> results, StreamSink<Exception> errors, MapAsyncOperation<TInput, TResult> operation, AsyncConcurrencyStrategyBase<TStrategyInput> strategy, Stream<Unit>? cancelAll = null, Stream<IReadOnlyCollection<TInput>>? cancelMatching = null, bool cancelOnDispose = true) where TInput : TStrategyInput
Parameters
sourceStream<TInput>The stream of inputs.
resultsStreamSink<TResult>The destination of the value of each run that succeeded, in the sequence of their ends.
errorsStreamSink<Exception>The destination of the exception of each run with an error.
operationMapAsyncOperation<TInput, TResult>The asynchronous work for each input.
strategyAsyncConcurrencyStrategyBase<TStrategyInput>The control of operations that overlap.
cancelAllStream<Unit>This is optional. Each send cancels each tracked operation.
cancelMatchingStream<IReadOnlyCollection<TInput>>This is optional. Each send cancels the tracked operations with a given input value.
cancelOnDisposeboolTrue when a disposal also cancels the tracked items. The default is true.
Returns
- AsyncMapStatus<TInput, TResult>
An AsyncMapStatus<TInput, TResult> that gives the Queued items, the Running items, and Execute. A disposal of it stops the pipeline.
Type Parameters
TInputThe type in the source stream.
TResultThe type that
operationgives when it succeeds.TStrategyInputThe input type of
strategy. The compiler infers it from the type ofstrategy, and no caller gives it explicitly. It is usuallyTInput. Thewhere TInput : TStrategyInputconstraint also lets more than one MapAsync call share a strategy that uses a base class or an interface, with its ownTInputin each call. The strategy then uses onlyTStrategyInput.
Exceptions
- ArgumentNullException
source,results,errors,operation, orstrategyis null.
MapAsync<TInput, TResult, TStrategyInput>(Stream<TInput>, StreamSink<TResult>, StreamSink<Exception>, MapAsyncOperation<TInput, TResult>, AsyncConcurrencyStrategyBase<TStrategyInput>, Func<TInput, TStrategyInput>, Stream<Unit>?, Stream<IReadOnlyCollection<TInput>>?, bool)
The fully general shape. Each other MapAsync overload is this overload with
a fixed converter. It is the only overload with no necessary relation
between TInput and
TStrategyInput, because the caller gives
inputConverter explicitly. Use a narrower overload
where one applies, because those overloads let most calls omit that
converter. Use this overload when the input type of
strategy has no inheritance relation to the
TInput of the call.
public static AsyncMapStatus<TInput, TResult> MapAsync<TInput, TResult, TStrategyInput>(this Stream<TInput> source, StreamSink<TResult> results, StreamSink<Exception> errors, MapAsyncOperation<TInput, TResult> operation, AsyncConcurrencyStrategyBase<TStrategyInput> strategy, Func<TInput, TStrategyInput> inputConverter, Stream<Unit>? cancelAll = null, Stream<IReadOnlyCollection<TInput>>? cancelMatching = null, bool cancelOnDispose = true)
Parameters
sourceStream<TInput>The stream of inputs. The pipeline gives each send to
strategy, and the strategy starts it immediately or makes it wait. After a disposal of the status, the pipeline ignores each subsequent send.resultsStreamSink<TResult>This is necessary. The pipeline sends the return value of each operation that succeeded here, in the sequence of their ends and not in the sequence of the inputs. The pipeline does not send a result from a run that a different run replaced, or from a run that a cancellation stopped. See
strategy.errorsStreamSink<Exception>This is necessary. The pipeline sends each operation with an error here. There is no call of this method with no destination for the errors.
operationMapAsyncOperation<TInput, TResult>The asynchronous work for each input. The pipeline calls it inline, thus it does not go to a thread pool before its own await. It receives a CancellationToken that combines the cancellation of this item with each token from the strategy. An operation that obeys that token lets
cancelAll,cancelMatching, andcancelOnDisposestop work that started. An operation that ignores the token continues to its end, and the cancellation then only stops the publication of its result. There is no overload with no token.strategyAsyncConcurrencyStrategyBase<TStrategyInput>The control of requests that overlap. A strategy instance holds no state of its own, and more than one MapAsync call can use the same instance safely, at the same time. Each call gets its own new state manager, thus two pipelines never share a scheduling state.
inputConverterFunc<TInput, TStrategyInput>Changes each
TInputvalue to theTStrategyInputofstrategy, before the admission.cancelAllStream<Unit>This is optional. Each send cancels each tracked operation, Queued or Running. The pipeline does not start a canceled Queued item at its turn. A cancellation stops a Running operation only if that operation monitors its CancellationToken.
cancelMatchingStream<IReadOnlyCollection<TInput>>This is optional. Each send cancels the tracked operations, Queued or Running, whose input value is in the collection of that send. This uses the default equality comparer for TInput. The limits of
cancelAllalso apply here.cancelOnDisposeboolTrue when a disposal of the AsyncMapStatus also cancels each item that the pipeline tracks at that time, Queued or Running. The default is true. At each value, a disposal always stops the admission of more values. This code sets the value here, at the setup, and not as a parameter of Dispose, because IDisposable.Dispose() is the only path to a disposal. A disposal does not stop the output. Each operation that runs continues to its end and publishes to
resultsor toerrorsafter the call returns. With true that output is usually not important, because the pipeline never publishes a canceled outcome and an operation that obeys its token makes none. An operation that ignores its token makes one, and with false that output is the purpose.
Returns
- AsyncMapStatus<TInput, TResult>
An AsyncMapStatus<TInput, TResult>. IsRunning is a Cell< bool> that is true while one call or more has the Running status, and a Queued item does not make it true. It updates with no glitch, in the transaction of the event that changes it. Items gives each tracked value with its status. Execute puts one value in, for an operation that drives a second pipeline. A disposal of the status stops the pipeline.
Type Parameters
TInputThe type in the source stream. It is the input for each call of
operation, the type in Items, and the type thatcancelMatchingcompares.TResultThe type that
operationgives when it succeeds. The pipeline sends it toresults.TStrategyInputThe input type of
strategy. The compiler infers it from the type ofstrategy, and no caller gives it explicitly. It needs no inheritance relation toTInput, becauseinputConvertermakes it explicitly.
Exceptions
- ArgumentNullException
source,results,errors,operation, orstrategyis null.