Open.ChannelExtensions 6.0.3

.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package Open.ChannelExtensions --version 6.0.3
NuGet\Install-Package Open.ChannelExtensions -Version 6.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Open.ChannelExtensions" Version="6.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Open.ChannelExtensions --version 6.0.3
#r "nuget: Open.ChannelExtensions, 6.0.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Open.ChannelExtensions as a Cake Addin
#addin nuget:?package=Open.ChannelExtensions&version=6.0.3

// Install Open.ChannelExtensions as a Cake Tool
#tool nuget:?package=Open.ChannelExtensions&version=6.0.3

Open.ChannelExtensions

NuGet

A set of extensions for optimizing/simplifying System.Threading.Channels usage.

Click here for detailed documentation.

Highlights

Read & Write

With optional concurrency levels.

  • Reading all entries in a channel.
  • Writing all entries from a source to a channel.
  • Piping (consuming) all entries to a buffer (channel).
  • .AsAsyncEnumerable() (IAsyncEnumerable) support for .NET Standard 2.1+ and .NET Core 3+

Special ChannelReader Operations

  • Filter
  • Transform
  • Batch
  • Join

Installation

Install-Package Open.ChannelExtensions

Examples

Being able to define an asynchronous pipeline with best practice usage using simple expressive syntax:

await Channel
    .CreateBounded<T>(10)
    .SourceAsync(source /* IEnumerable<Task<T>> */)
    .PipeAsync(
        maxConcurrency: 2,
        capacity: 5,
        transform: asyncTransform01)
    .Pipe(transform02, /* capacity */ 3)
    .ReadAllAsync(finalTransformedValue => {
        // Do something async with each final value.
    });
await source /* IEnumerable<T> */
    .ToChannel(boundedSize: 10, singleReader: true)
    .PipeAsync(asyncTransform01, /* capacity */ 5)
    .Pipe(
        maxConcurrency: 2,
        capacity: 3,
        transform: transform02)
    .ReadAll(finalTransformedValue => {
        // Do something with each final value.
    });

Reading (until the channel is closed)

One by one read each entry from the channel
await channel.ReadAll(
    entry => { /* Processing Code */ });
await channel.ReadAll(
    (entry, index) => { /* Processing Code */ });
await channel.ReadAllAsync(
    async entry => { await /* Processing Code */ });
await channel.ReadAllAsync(
    async (entry, index) => { await /* Processing Code */ });
Read concurrently each entry from the channel
await channel.ReadAllConcurrently(
    maxConcurrency,
    entry => { /* Processing Code */ });
await channel.ReadAllConcurrentlyAsync(
    maxConcurrency,
    async entry => { await /* Processing Code */ });

Writing

If complete is true, the channel will be closed when the source is empty.

Dump a source enumeration into the channel
// source can be any IEnumerable<T>.
await channel.WriteAll(source, complete: true);
// source can be any IEnumerable<Task<T>> or IEnumerable<ValueTask<T>>.
await channel.WriteAllAsync(source, complete: true);
Synchronize reading from the source and process the results concurrently
// source can be any IEnumerable<Task<T>> or IEnumerable<ValueTask<T>>.
await channel.WriteAllConcurrentlyAsync(
    maxConcurrency, source, complete: true);

Filter & Transform

// Filter and transform when reading.
channel.Reader
    .Filter(predicate) // .Where()
    .Transform(selector) // .Select()
    .ReadAllAsync(async value => {/*...*/});

Batching

values.Reader
    .Batch(10 /*batch size*/)
    .WithTimeout(1000) // Any non-empty batches are flushed every second.
    .ReadAllAsync(async batch => {/*...*/});

Joining

batches.Reader
    .Join()
    .ReadAllAsync(async value => {/*...*/});

Pipelining / Transforming

Transform and buffer entries
// Transform values in a source channel to new unbounded channel.
var transformed = channel.Pipe(
    async value => /* transformation */);
// Transform values in a source channel to new unbounded channel with a max concurrency of X.
const X = 4;
var transformed = channel.Pipe(
    X, async value => /* transformation */);
// Transform values in a source channel to new bounded channel bound of N entries.
const N = 5;
var transformed = channel.Pipe(
    async value => /* transformation */, N);
// Transform values in a source channel to new bounded channel bound of N entries with a max concurrency of X.
const X = 4;
const N = 5;
var transformed = channel.Pipe(
    X, async value => /* transformation */, N);

// or
transformed = channel.Pipe(
    maxConcurrency: X,
    capacity: N,
    transform: async value => /* transformation */);
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Open.ChannelExtensions:

Package Downloads
Open.Database.Extensions.Channel

Database extensions for pipelining data through channels. Includes Open.Database.Extensions.Core.

DataPipe.Core

Provides AWS support to the DataPipe platform. Reference this package if you need to read or write to S3 from a data pipe script

Resistance.Postgres

.NET toolkit for PostgreSQL

Pype.Background.Channels

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Open.ChannelExtensions:

Repository Stars
WolvenKit/WolvenKit
Mod editor/creator for RED Engine games. The point is to have an all in one tool for creating mods for the games made with the engine.
Version Downloads Last updated
6.2.2 11,910 10/5/2022
6.2.1 7,889 9/3/2022
6.2.0 13,790 7/13/2022
6.1.0 3,398 6/30/2022
6.0.3 12,534 5/12/2022
6.0.2 12,080 4/13/2022
6.0.1 16,037 3/1/2022
6.0.0 1,414 2/22/2022
5.2.1 2,716 2/22/2022
5.2.0 2,961 2/6/2022
5.1.3 24,411 10/12/2021
5.1.2 499 10/8/2021
5.1.1 207 10/8/2021
5.1.0 222 10/8/2021
5.0.0 23,037 6/16/2021
3.5.0 107,259 7/16/2020
3.4.0 4,877 6/3/2020
3.3.2 398 6/1/2020
3.3.1 414 5/14/2020
3.3.0 3,833 2/19/2020
2.6.0 404 10/20/2019