### Install Open.ChannelExtensions NuGet Package Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Instructions for installing the Open.ChannelExtensions library via NuGet package manager. ```nuget Install-Package Open.ChannelExtensions ``` -------------------------------- ### Install Open.ChannelExtensions NuGet Package Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Shows how to install the Open.ChannelExtensions library using the NuGet package manager. ```nuget Install-Package Open.ChannelExtensions ``` -------------------------------- ### Source to Channel Pipeline Example (C#) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docfx/index.md Illustrates converting an IEnumerable source into a channel pipeline. This example covers creating a channel from a source, applying transformations, and reading the final results. ```cs await source /* IEnumerable */ .ToChannel(boundedSize: 10, singleReader: true) .PipeAsync(asyncTransform01, /* capacity */ 5) .Pipe( maxConcurrency: 2, capacity: 3, transform: transform02) .ReadAll(finalTransformedValue => { // Do something with each final value. }); ``` -------------------------------- ### Channel Pipeline Example (C#) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docfx/index.md Demonstrates building an asynchronous pipeline using Channel extensions. It shows creating a bounded channel, sourcing data, and applying transformations with concurrency and capacity controls. ```cs await Channel .CreateBounded(10) .SourceAsync(source /* IEnumerable> */) .PipeAsync( maxConcurrency: 2, capacity: 5, transform: asyncTransform01) .Pipe(transform02, /* capacity */ 3) .ReadAllAsync(finalTransformedValue => { // Do something async with each final value. }); ``` -------------------------------- ### Pipeline with ToChannel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Illustrates building a pipeline starting from an `IEnumerable` using `ToChannel`, followed by `PipeAsync` and `Pipe` transformations, and concluding with `ReadAll` for processing. ```C# await source /* IEnumerable */ .ToChannel(boundedSize: 10, singleReader: true) .PipeAsync(asyncTransform01, /* capacity */ 5) .Pipe( maxConcurrency: 2, capacity: 3, transform: transform02) .ReadAll(finalTransformedValue => { // Do something with each final value. }); ``` -------------------------------- ### Async Pipeline with ToChannel and Pipe Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Illustrates creating an asynchronous pipeline starting from a standard IEnumerable. It converts the enumerable to a channel, applies transformations with concurrency, and consumes the results. ```csharp await source /* IEnumerable */ .ToChannel(boundedSize: 10, singleReader: true) .PipeAsync(asyncTransform01, /* capacity */ 5) .Pipe( maxConcurrency: 2, capacity: 3, transform: transform02) .ReadAll(finalTransformedValue => { // Do something with each final value. }); ``` -------------------------------- ### Asynchronous Pipeline with SourceAsync and PipeAsync Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/index.html Demonstrates building an asynchronous pipeline starting with a channel created from `CreateBounded`, sourcing data using `SourceAsync`, applying transformations with `PipeAsync` and `Pipe`, and finally reading results with `ReadAllAsync`. This showcases complex asynchronous data flow management. ```C# await Channel .CreateBounded(10) .SourceAsync(source /* IEnumerable> */) .PipeAsync( maxConcurrency: 2, capacity: 5, transform: asyncTransform01) .Pipe(transform02, /* capacity */ 3) .ReadAllAsync(finalTransformedValue => { // Do something async with each final value. }); ``` -------------------------------- ### Transform and Buffer Entries (Pipe) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Provides examples of transforming channel entries into new channels, with options for unbounded/bounded capacities and controlling concurrency for asynchronous transformations. ```csharp // Transform values in a source channel to new unbounded channel. var transformed = channel.Pipe( async value => /* transformation *\/); ``` ```csharp // 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 *\/); ``` ```csharp // 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); ``` ```csharp // 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); ``` ```csharp // or transformed = channel.Pipe( maxConcurrency: X, capacity: N, transform: async value => /* transformation *\/); ``` -------------------------------- ### Async Pipeline with SourceAsync and PipeAsync Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Demonstrates building an asynchronous data processing pipeline. It starts with a source of asynchronous tasks, pipes them through transformations with concurrency control, and finally reads all processed entries. ```csharp await Channel .CreateBounded(10) .SourceAsync(source /* IEnumerable> */) .PipeAsync( maxConcurrency: 2, capacity: 5, transform: asyncTransform01) .Pipe(transform02, /* capacity */ 3) .ReadAllAsync(finalTransformedValue => { // Do something async with each final value. }); ``` -------------------------------- ### Async Pipeline with ToChannel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Demonstrates converting an enumerable source into a channel, piping it through asynchronous and synchronous transformations with specified concurrency and capacity, and then reading all results. ```csharp await source /* IEnumerable *\/ .ToChannel(boundedSize: 10, singleReader: true) .PipeAsync(asyncTransform01, /* capacity *\/ 5) .Pipe( maxConcurrency: 2, capacity: 3, transform: transform02) .ReadAll(finalTransformedValue => { // Do something with each final value. }); ``` -------------------------------- ### Async Pipeline with SourceAsync Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Demonstrates creating a bounded channel, sourcing data asynchronously from an enumerable of tasks, and piping it through asynchronous and synchronous transformations before reading all results. ```csharp await Channel .CreateBounded(10) .SourceAsync(source /\* IEnumerable> *\/) .PipeAsync( maxConcurrency: 2, capacity: 5, transform: asyncTransform01) .Pipe(transform02, /* capacity *\/ 3) .ReadAllAsync(finalTransformedValue => { // Do something async with each final value. }); ``` -------------------------------- ### Async Pipeline with SourceAsync Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Demonstrates creating an asynchronous pipeline using `SourceAsync` to feed a channel, followed by `PipeAsync` and `Pipe` transformations, and finally `ReadAllAsync` for processing. ```C# await Channel .CreateBounded(10) .SourceAsync(source /* IEnumerable> */) .PipeAsync( maxConcurrency: 2, capacity: 5, transform: asyncTransform01) .Pipe(transform02, /* capacity */ 3) .ReadAllAsync(finalTransformedValue => { // Do something async with each final value. }); ``` -------------------------------- ### Read All Entries One by One Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Shows how to read each entry from a channel sequentially using both synchronous and asynchronous processing callbacks. ```csharp await channel.ReadAll( entry => { /* Processing Code *\/ }); ``` ```csharp await channel.ReadAll( (entry, index) => { /* Processing Code *\/ }); ``` ```csharp await channel.ReadAllAsync( async entry => { await /* Processing Code *\/ }); ``` ```csharp await channel.ReadAllAsync( async (entry, index) => { await /* Processing Code *\/ }); ``` -------------------------------- ### Asynchronous Pipeline with ToChannel and Pipe Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/index.html Illustrates converting an `IEnumerable` source into a channel using `ToChannel`, then applying asynchronous and synchronous transformations via `PipeAsync` and `Pipe` before consuming the results with `ReadAll`. This pattern simplifies data processing from collections. ```C# await source /* IEnumerable */ .ToChannel(boundedSize: 10, singleReader: true) .PipeAsync(asyncTransform01, /* capacity */ 5) .Pipe( maxConcurrency: 2, capacity: 3, transform: transform02) .ReadAll(finalTransformedValue => { // Do something with each final value. }); ``` -------------------------------- ### ReadAll: Read entries one by one from a channel (C#) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docfx/index.md Provides methods to read each entry from a channel sequentially. Supports both synchronous and asynchronous processing delegates, with and without an index. ```cs await channel.ReadAll( entry => { /* Processing Code */ }); ``` ```cs await channel.ReadAll( (entry, index) => { /* Processing Code */ }); ``` ```cs await channel.ReadAllAsync( async entry => { await /* Processing Code */ }); ``` ```cs await channel.ReadAllAsync( async (entry, index) => { await /* Processing Code */ }); ``` -------------------------------- ### Write All Entries to Channel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Illustrates writing all entries from an enumerable source into a channel, with an option to complete the channel once the source is exhausted. ```csharp // source can be any IEnumerable. await channel.WriteAll(source, complete: true); ``` ```csharp // source can be any IEnumerable> or IEnumerable>. await channel.WriteAllAsync(source, complete: true); ``` -------------------------------- ### Pipelining: Transform to Bounded Channel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Transforms entries from a source channel into a new bounded channel with a specified capacity, using an asynchronous transformation function. ```csharp // 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); ``` -------------------------------- ### Read Channel Entries One by One (Synchronous with Index) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Reads each entry from a channel sequentially, providing both the entry and its index to a synchronous callback function. ```csharp await channel.ReadAll( (entry, index) => { /* Processing Code */ }); ``` -------------------------------- ### Write All Entries Concurrently Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Shows how to write entries from an enumerable source of tasks into a channel concurrently, managing the number of parallel operations and optionally completing the channel. ```csharp // source can be any IEnumerable> or IEnumerable>. await channel.WriteAllConcurrentlyAsync( maxConcurrency, source, complete: true); ``` -------------------------------- ### Read Channel Entries One by One (Asynchronous with Index) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Reads each entry from a channel sequentially, providing both the entry and its index to an asynchronous callback function. ```csharp await channel.ReadAllAsync( async (entry, index) => { await /* Processing Code */ }); ``` -------------------------------- ### Read All Entries One by One Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Provides methods to read all entries from a channel sequentially, supporting both synchronous and asynchronous processing delegates. ```C# await channel.ReadAll( entry => { /* Processing Code */ }); ``` ```C# await channel.ReadAll( (entry, index) => { /* Processing Code */ }); ``` ```C# await channel.ReadAllAsync( async entry => { await /* Processing Code */ }); ``` ```C# await channel.ReadAllAsync( async (entry, index) => { await /* Processing Code */ }); ``` -------------------------------- ### PipeAsync (ChannelReader, Func>, ...) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Reads all entries from a source channel, applies a transform function to each entry, and buffers the results into a new ChannelReader. The transform function is applied sequentially. ```APIDOC PipeAsync (ChannelReader source, Func> transform, int capacity = -1, bool singleReader = false, CancellationToken cancellationToken = default(CancellationToken)) Reads all entries and applies the values to the provided transform function before buffering the results into another channel for consumption. Parameters: source: System.Threading.Channels.ChannelReader - The source channel. transform: System.Func> - The transform function to apply the source entries before passing on to the output. capacity: System.Int32 - The width of the pipe: how many entries to buffer while waiting to be read from. singleReader: System.Boolean - True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur. cancellationToken: System.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the output. ``` -------------------------------- ### ReadAll with Index (Synchronous Callback) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/index.html Reads entries from a channel one by one until the channel is closed, providing both the entry and its sequential index to a synchronous callback function. ```C# await channel.ReadAll( (entry, index) => { /* Processing Code */ }); ``` -------------------------------- ### Read Channel Entries One by One (Synchronous) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Reads each entry from a channel sequentially using a synchronous callback function for processing. ```csharp await channel.ReadAll( entry => { /* Processing Code */ }); ``` -------------------------------- ### ChannelExtensions Source Method Overloads Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Provides documentation for the `Source` extension methods in ChannelExtensions. These methods write entries from various data sources (IEnumerable, IAsyncEnumerable) into a target channel, returning a ChannelReader. They handle deferred execution and cancellation tokens. ```APIDOC Source(Channel, IAsyncEnumerable, CancellationToken) - Executes all entries from the source and passes their result to the channel. Calls complete when finished. - Declaration: public static ChannelReader Source(this Channel target, IAsyncEnumerable source, CancellationToken cancellationToken) - Parameters: - target: System.Threading.Channels.Channel - The channel to write to. - source: System.Collections.Generic.IAsyncEnumerable - The asynchronous source data to use. - cancellationToken: System.Threading.CancellationToken - The cancellation token. - Returns: - System.Threading.Channels.ChannelReader - The channel reader. - Type Parameters: - TWrite: The input type of the channel. - TRead: The output type of the channel. ``` ```APIDOC Source(Channel, IEnumerable, Boolean, CancellationToken) - Writes all entries from the source to the channel. Calls complete when finished. - Declaration: public static ChannelReader Source(this Channel target, IEnumerable source, bool deferredExecution = false, CancellationToken cancellationToken = default(CancellationToken)) - Parameters: - target: System.Threading.Channels.Channel - The channel to write to. - source: System.Collections.Generic.IEnumerable - The source data to use. - deferredExecution: System.Boolean - If true, calls await Task.Yield() before writing to the channel. - cancellationToken: System.Threading.CancellationToken - An optional cancellation token. - Returns: - System.Threading.Channels.ChannelReader - The channel reader. - Type Parameters: - TWrite: The input type of the channel. - TRead: The output type of the channel. ``` -------------------------------- ### Pipelining: Transform to Bounded Channel with Concurrency Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Transforms entries from a source channel into a new bounded channel with a specified capacity, processing items concurrently up to a specified maximum concurrency level. ```csharp // 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 */); ``` -------------------------------- ### ReadAll (Synchronous Callback) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/index.html Reads entries from a channel one by one until the channel is closed. This overload accepts a synchronous callback function to process each entry. ```C# await channel.ReadAll( entry => { /* Processing Code */ }); ``` -------------------------------- ### Pipelining: Transform to Unbounded Channel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Transforms entries from a source channel into a new unbounded channel using an asynchronous transformation function. ```csharp // Transform values in a source channel to new unbounded channel. var transformed = channel.Pipe( async value => /* transformation */); ``` -------------------------------- ### Read Channel Entries One by One (Asynchronous) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Reads each entry from a channel sequentially using an asynchronous callback function for processing. ```csharp await channel.ReadAllAsync( async entry => { await /* Processing Code */ }); ``` -------------------------------- ### ReadAll Channel Extensions Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/Open.ChannelExtensions.TransformChannel-2.html Extension methods for reading all items from a channel synchronously using Action-based delegates. Supports cancellation and optional parameters for controlling behavior. ```APIDOC Extensions.ReadAll(Channel channel, Action readAction, Boolean continueOnCapturedContext, CancellationToken cancellationToken) - Reads all items from the channel, invoking the provided synchronous action for each item. - Parameters: - channel: The channel to read from. - readAction: A delegate that processes each item read from the channel, receiving the item and its index. - continueOnCapturedContext: A boolean indicating whether to capture and resume the current context. - cancellationToken: A token to observe for cancellation requests. - Returns: A Task representing the asynchronous operation. Extensions.ReadAll(Channel channel, Action readAction, CancellationToken cancellationToken, Boolean continueOnCapturedContext) - Overload with different parameter order for cancellationToken and continueOnCapturedContext. Extensions.ReadAll(Channel channel, CancellationToken cancellationToken, Action readAction, Boolean continueOnCapturedContext) - Overload with different parameter order for cancellationToken and readAction. Extensions.ReadAll(Channel channel, Action readAction, Boolean continueOnCapturedContext, CancellationToken cancellationToken) - Reads all items from the channel, invoking the provided synchronous action for each item. - Parameters: - channel: The channel to read from. - readAction: A delegate that processes each item read from the channel. - continueOnCapturedContext: A boolean indicating whether to capture and resume the current context. - cancellationToken: A token to observe for cancellation requests. - Returns: A Task representing the asynchronous operation. Extensions.ReadAll(Channel channel, Action readAction, CancellationToken cancellationToken, Boolean continueOnCapturedContext) - Overload with different parameter order for cancellationToken and continueOnCapturedContext. ``` -------------------------------- ### Joining Batches Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Combines multiple batches of items, previously grouped by the `Batch` operation, back into a single stream of individual items. ```C# batches.Reader .Join() // Combines the batches into a single channel. .ReadAllAsync(async value => {/*...*/}); ``` -------------------------------- ### ChannelExtensions.ToChannelAsync Methods Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Provides methods to write entries from an asynchronous source to a channel, with various configuration options for capacity, concurrency, and reader optimization. ```APIDOC ToChannelAsync(IEnumerable>, Int32, Boolean, Int32, CancellationToken) Writes all entries from the source to a channel and calls complete when finished. Declaration: public static ChannelReader ToChannelAsync(this IEnumerable> source, int capacity = -1, bool singleReader = false, int maxConcurrency = 1, CancellationToken cancellationToken = default(CancellationToken)) Parameters: source: System.Collections.Generic.IEnumerable> - The asynchronous source data to use. capacity: System.Int32 - The optional bounded capacity of the channel. Default is unbound. singleReader: System.Boolean - True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur. maxConcurrency: System.Int32 - The maximum number of concurrent operations. Greater than 1 may likely cause results to be out of order. cancellationToken: System.Threading.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the results. Type Parameters: T - The input type of the channel. ``` ```APIDOC ToChannelAsync(IEnumerable>, ChannelOptions, Int32, CancellationToken) Writes all entries from the source to a channel and calls complete when finished. Declaration: public static ChannelReader ToChannelAsync(this IEnumerable> source, ChannelOptions channelOptions, int maxConcurrency = 1, CancellationToken cancellationToken = default(CancellationToken)) Parameters: source: System.Collections.Generic.IEnumerable> - The asynchronous source data to use. channelOptions: System.Threading.Channels.ChannelOptions - The options for configuring the new channel. maxConcurrency: System.Int32 - The maximum number of concurrent operations. Greater than 1 may likely cause results to be out of order. cancellationToken: System.Threading.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the results. Type Parameters: T - The input type of the channel. ``` ```APIDOC ToChannelAsync(IEnumerable>, Int32, Boolean, Int32, CancellationToken) Writes all entries from the source to a channel and calls complete when finished. Declaration: public static ChannelReader ToChannelAsync(this IEnumerable> source, int capacity = -1, bool singleReader = false, int maxConcurrency = 1, CancellationToken cancellationToken = default(CancellationToken)) Parameters: source: System.Collections.Generic.IEnumerable> - The asynchronous source data to use. capacity: System.Int32 - The optional bounded capacity of the channel. Default is unbound. singleReader: System.Boolean - True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur. maxConcurrency: System.Int32 - The maximum number of concurrent operations. Greater than 1 may likely cause results to be out of order. cancellationToken: System.Threading.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the results. Type Parameters: T - The input type of the channel. ``` -------------------------------- ### Read All Entries Concurrently Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/index.html Demonstrates reading all entries from a channel concurrently, specifying the maximum number of concurrent operations for both synchronous and asynchronous processing. ```csharp await channel.ReadAllConcurrently( maxConcurrency, entry => { /* Processing Code *\/ }); ``` ```csharp await channel.ReadAllConcurrentlyAsync( maxConcurrency, async entry => { await /* Processing Code *\/ }); ``` -------------------------------- ### Write All Entries to Channel Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Dumps an enumeration of items or asynchronous tasks into a channel, with an option to complete the channel when the source is exhausted. ```C# // source can be any IEnumerable. await channel.WriteAll(source, complete: true); ``` ```C# // source can be any IEnumerable> or IEnumerable>. await channel.WriteAllAsync(source, complete: true); ``` -------------------------------- ### ReadAll (ChannelReader, Action, Boolean) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Reads all entries from a source channel and processes each item using a provided action delegate. The action receives the item and its index. This method is useful for iterating through channel data and performing operations on each element, with an option to control processing based on a boolean flag. ```APIDOC ReadAll(ChannelReader source, Action action, bool continueOnCapturedContext, CancellationToken cancellationToken = default(CancellationToken)) - Reads all entries from the source channel and processes each item with the provided action. - Parameters: - source: System.Threading.Channels.ChannelReader - The source channel. - action: System.Action - The action to perform on each item, receiving the item and its index. - continueOnCapturedContext: System.Boolean - A value indicating whether to capture and resume the current context on the target thread. - cancellationToken: System.Threading.CancellationToken - An optional cancellation token. - Type Parameters: - T: The type contained by the source channel. ``` -------------------------------- ### PipeTo (ChannelReader, Channel) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Reads all entries from a source channel and writes them to a target channel. It automatically calls complete on the target when the source is finished and propagates any errors. This method is useful for managing different buffer sizes, especially when the source reader originates from a transformation function. ```APIDOC PipeTo(ChannelReader source, Channel target, CancellationToken cancellationToken = default(CancellationToken)) - Reads all entries from the source channel and writes them to the target. - Calls complete on the target when finished and propagates any errors. - Useful for managing different buffer sizes. - Parameters: - source: System.Threading.Channels.ChannelReader - The source channel. - target: System.Threading.Channels.Channel - The target channel. - cancellationToken: System.Threading.CancellationToken - An optional cancellation token. - Returns: - System.Threading.Channels.ChannelReader - The channel reader of the target. - Type Parameters: - T: The type contained by the source channel and written to the target. ``` -------------------------------- ### Batching Channel Entries Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/README.md Groups items read from a channel into batches (e.g., `List`) and allows flushing batches based on size or a timeout. ```C# values.Reader .Batch(10 /*batch size*/) // Groups into List. .WithTimeout(1000) // Any non-empty batches are flushed every second. .ReadAllAsync(async batch => {/*...*/}); ``` -------------------------------- ### PipeAsync (ChannelReader, Func>, ...) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/Open.ChannelExtensions.Extensions.html Reads all entries from a source channel, applies a transform function to each entry, and buffers the results into a new ChannelReader. The transform function is applied sequentially. ```APIDOC PipeAsync (ChannelReader source, Func> transform, int capacity = -1, bool singleReader = false, CancellationToken cancellationToken = default(CancellationToken)) Reads all entries and applies the values to the provided transform function before buffering the results into another channel for consumption. Parameters: source: System.Threading.Channels.ChannelReader - The source channel. transform: System.Func> - The transform function to apply the source entries before passing on to the output. capacity: System.Int32 - The width of the pipe: how many entries to buffer while waiting to be read from. singleReader: System.Boolean - True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur. cancellationToken: System.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the output. ``` -------------------------------- ### ChannelExtensions Source Method Overloads Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/Open.ChannelExtensions.Extensions.html Provides documentation for the `Source` extension methods in ChannelExtensions. These methods write entries from various data sources (IEnumerable, IAsyncEnumerable) into a target channel, returning a ChannelReader. They handle deferred execution and cancellation tokens. ```APIDOC Source(Channel, IAsyncEnumerable, CancellationToken) - Executes all entries from the source and passes their result to the channel. Calls complete when finished. - Declaration: public static ChannelReader Source(this Channel target, IAsyncEnumerable source, CancellationToken cancellationToken) - Parameters: - target: System.Threading.Channels.Channel - The channel to write to. - source: System.Collections.Generic.IAsyncEnumerable - The asynchronous source data to use. - cancellationToken: System.Threading.CancellationToken - The cancellation token. - Returns: - System.Threading.Channels.ChannelReader - The channel reader. - Type Parameters: - TWrite: The input type of the channel. - TRead: The output type of the channel. ``` ```APIDOC Source(Channel, IEnumerable, Boolean, CancellationToken) - Writes all entries from the source to the channel. Calls complete when finished. - Declaration: public static ChannelReader Source(this Channel target, IEnumerable source, bool deferredExecution = false, CancellationToken cancellationToken = default(CancellationToken)) - Parameters: - target: System.Threading.Channels.Channel - The channel to write to. - source: System.Collections.Generic.IEnumerable - The source data to use. - deferredExecution: System.Boolean - If true, calls await Task.Yield() before writing to the channel. - cancellationToken: System.Threading.CancellationToken - An optional cancellation token. - Returns: - System.Threading.Channels.ChannelReader - The channel reader. - Type Parameters: - TWrite: The input type of the channel. - TRead: The output type of the channel. ``` -------------------------------- ### ReadAllConcurrently: Read entries concurrently from a channel (C#) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docfx/index.md Enables reading and processing entries from a channel concurrently. Requires specifying the maximum number of concurrent operations and a processing delegate. ```cs await channel.ReadAllConcurrently( maxConcurrency, entry => { /* Processing Code */ }); ``` ```cs await channel.ReadAllConcurrentlyAsync( maxConcurrency, async entry => { await /* Processing Code */ }); ``` -------------------------------- ### Pipe with Capacity and Transform (C#) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Reads entries from a source channel, applies a transform function, and buffers results into a new channel. It handles buffering, concurrency, and cancellation for efficient data processing. ```APIDOC Pipe (Channel source, Func transform, int capacity = -1, bool singleReader = false, CancellationToken cancellationToken = default(CancellationToken)) Reads all entries and applies the values to the provided transform function before buffering the results into another channel for consumption. Declaration: public static ChannelReader Pipe(this Channel source, Func transform, int capacity = -1, bool singleReader = false, CancellationToken cancellationToken = default(CancellationToken)) Parameters: source: System.Threading.Channels.Channel - The source channel. transform: System.Func - The transform function to apply the source entries before passing on to the output. capacity: System.Int32 - The width of the pipe: how many entries to buffer while waiting to be read from. singleReader: System.Boolean - True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur. cancellationToken: System.CancellationToken - An optional cancellation token. Returns: System.Threading.Channels.ChannelReader - The channel reader containing the output. Type Parameters: TWrite: The type being accepted by the channel. TRead: The type contained by the source channel. TOut: The outgoing type from the resultant channel. ``` -------------------------------- ### ReadAll (ChannelReader, Action, Boolean) Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/api/Open.ChannelExtensions.Extensions.html Reads all entries from a source channel and processes each item using a provided action delegate. The action receives the item and its index. This method is useful for iterating through channel data and performing operations on each element, with an option to control processing based on a boolean flag. ```APIDOC ReadAll(ChannelReader source, Action action, bool continueOnCapturedContext, CancellationToken cancellationToken = default(CancellationToken)) - Reads all entries from the source channel and processes each item with the provided action. - Parameters: - source: System.Threading.Channels.ChannelReader - The source channel. - action: System.Action - The action to perform on each item, receiving the item and its index. - continueOnCapturedContext: System.Boolean - A value indicating whether to capture and resume the current context on the target thread. - cancellationToken: System.Threading.CancellationToken - An optional cancellation token. - Type Parameters: - T: The type contained by the source channel. ``` -------------------------------- ### Batch Channel Entries with Timeout Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/Open.ChannelExtensions/README.md Groups channel entries into batches of a specified size. Batches are flushed either when full or after a timeout period, allowing for processing of multiple items at once. ```csharp values.Reader .Batch(10 /*batch size*/) .WithTimeout(1000) // Any non-empty batches are flushed every second. .ReadAllAsync(async batch => {/*...*/}); ``` -------------------------------- ### ReadAll Channel Extension Methods Source: https://github.com/open-net-libraries/open.channelextensions/blob/master/docs/Open.ChannelExtensions.Extensions.html Reads items from a channel and passes them to a receiver. These methods handle deferred execution and cancellation tokens, providing the count of items read upon completion. Overloads differ in parameter order and the signature of the receiver action. ```APIDOC ReadAll(Channel, Action, Boolean, CancellationToken) Reads items from the channel and passes them to the receiver. Parameters: channel: System.Threading.Channels.Channel - The channel to read from. receiver: System.Action - The receiver function. deferredExecution: System.Boolean - If true, calls await Task.Yield() before reading. cancellationToken: System.Threading.CancellationToken - An optional cancellation token. Returns: System.Threading.Tasks.ValueTask - The count of items read after the reader has completed. ReadAll(Channel, Action, CancellationToken, Boolean) Reads items from the channel and passes them to the receiver. Parameters: channel: System.Threading.Channels.Channel - The channel to read from. receiver: System.Action - The receiver function. cancellationToken: System.Threading.CancellationToken - The optional cancellation token. deferredExecution: System.Boolean - If true, calls await Task.Yield() before reading. Returns: System.Threading.Tasks.ValueTask - The count of items read after the reader has completed. ReadAll(Channel, CancellationToken, Action, Boolean) Reads items from the channel and passes them to the receiver, providing the item count to the receiver. Parameters: channel: System.Threading.Channels.Channel - The channel to read from. cancellationToken: System.Threading.CancellationToken - The optional cancellation token. receiver: System.Action - The receiver function, which receives the item and its count. deferredExecution: System.Boolean - If true, calls await Task.Yield() before reading. Returns: System.Threading.Tasks.ValueTask - The count of items read after the reader has completed. ```