Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Jac21/BlockingCollectionExtensions

Open more actions menu

Repository files navigation

logo

NuGet Status MIT Licence CI donate

Helpers and adapters for working with BlockingCollection<T> in modern .NET applications.

Installation

Find it on nuget!

PM> Install-Package BlockingCollectionExtensions -Version 7.0.1

What's New

  • Simpler IProducerConsumerCollection<T> adapters with better defaults
  • TimeSpan-based overloads and optional cancellation tokens
  • IAsyncEnumerable<T> support for async-first producer pipelines
  • Modernized package metadata, symbols, readme packaging, and CI

Usage

Add from an enumerable

using System.Collections.Concurrent;
using BlockingCollectionExtensions;

var collection = new BlockingCollection<int>();
collection.AddFromEnumerable(new[] { 1, 2, 3 }, completeAddingWhenDone: true);

Add from an async enumerable

using System.Collections.Concurrent;
using BlockingCollectionExtensions;

var collection = new BlockingCollection<int>();

await collection.AddFromAsyncEnumerable(GetItemsAsync(), completeAddingWhenDone: true);

static async IAsyncEnumerable<int> GetItemsAsync()
{
    yield return 1;
    await Task.Yield();
    yield return 2;
}

Adapt to IProducerConsumerCollection<T>

using System.Collections.Concurrent;
using BlockingCollectionExtensions;

var collection = new BlockingCollection<int>();
var adapter = collection.AsProducerConsumerCollection(TimeSpan.FromMilliseconds(250));

adapter.TryAdd(42);
adapter.TryTake(out var value);

Target Frameworks

  • net8.0
  • netstandard2.1

Notes

  • BlockingCollection<T> is still useful for some producer/consumer scenarios, especially when interop with older code matters.
  • For brand new async-heavy pipelines, System.Threading.Channels may still be the better default choice.

About

📎 Utilities to aid in utilizing the ever-useful .NET structure BlockingCollection<T>

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.