/// <summary> /// Pipes the source data through a single producer constrained TransformBlock with the specified bounded capacity. /// </summary> /// <typeparam name="TIn">The input type.</typeparam> /// <typeparam name="TOut">The output type.</typeparam> /// <param name="source">The source block to receive from.</param> /// <param name="capacity">The bounded capacity of the transform block</param> /// <param name="transform">The async transform function to apply.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>The TransformBlock created.</returns> public static IReceivableSourceBlock <TOut> PipeLimitedAsync <TIn, TOut>(this ISourceBlock <TIn> source, int capacity, Func <TIn, Task <TOut> > transform, CancellationToken cancellationToken = default) => source.PipeAsync(transform, new ExecutionDataflowBlockOptions { BoundedCapacity = capacity, SingleProducerConstrained = true, CancellationToken = cancellationToken });
/// <summary> /// Pipes the source data through a single producer constrained TransformBlock with the specified max concurrency. /// </summary> /// <typeparam name="TIn">The input type.</typeparam> /// <typeparam name="TOut">The output type.</typeparam> /// <param name="source">The source block to receive from.</param> /// <param name="maxConcurrency">The maximum concurrency of the transform block</param> /// <param name="transform">The async transform function to apply.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>The TransformBlock created.</returns> public static IReceivableSourceBlock <TOut> PipeConcurrentlyAsync <TIn, TOut>(this ISourceBlock <TIn> source, int maxConcurrency, Func <TIn, Task <TOut> > transform, CancellationToken cancellationToken = default) => source.PipeAsync(transform, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxConcurrency, SingleProducerConstrained = true, CancellationToken = cancellationToken });
/// <summary> /// Pipes the source data through a single producer constrained ActionBlock with the specified bounded capacity. /// </summary> /// <typeparam name="T">The input type.</typeparam> /// <param name="source">The source block to receive from.</param> /// <param name="capacity">The bounded capacity of the transform block</param> /// <param name="handler">The async handler function to apply.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>The ActionBlock created.</returns> public static ActionBlock <T> PipeLimitedAsync <T>(this ISourceBlock <T> source, int capacity, Func <T, Task> handler, CancellationToken cancellationToken = default) => source.PipeAsync(handler, new ExecutionDataflowBlockOptions { BoundedCapacity = capacity, SingleProducerConstrained = true, CancellationToken = cancellationToken });
/// <summary> /// Pipes the source data through a single producer constrained ActionBlock with the specified max concurrency. /// </summary> /// <typeparam name="T">The input type.</typeparam> /// <param name="source">The source block to receive from.</param> /// <param name="maxConcurrency">The maximum concurrency of the action block</param> /// <param name="handler">The async handler function to apply.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>The ActionBlock created.</returns> public static ActionBlock <T> PipeConcurrentlyAsync <T>(this ISourceBlock <T> source, int maxConcurrency, Func <T, Task> handler, CancellationToken cancellationToken = default) => source.PipeAsync(handler, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxConcurrency, SingleProducerConstrained = true, CancellationToken = cancellationToken });