Skip to content

Repository files navigation

logo

NuGet StatusMIT LicenceCIdonate

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

usingSystem.Collections.Concurrent;usingBlockingCollectionExtensions;varcollection=newBlockingCollection<int>();collection.AddFromEnumerable(new[]{1,2,3},completeAddingWhenDone:true);

Add from an async enumerable

usingSystem.Collections.Concurrent;usingBlockingCollectionExtensions;varcollection=newBlockingCollection<int>();awaitcollection.AddFromAsyncEnumerable(GetItemsAsync(),completeAddingWhenDone:true);staticasyncIAsyncEnumerable<int>GetItemsAsync(){yieldreturn1;awaitTask.Yield();yieldreturn2;}

Adapt to IProducerConsumerCollection<T>

usingSystem.Collections.Concurrent;usingBlockingCollectionExtensions;varcollection=newBlockingCollection<int>();varadapter=collection.AsProducerConsumerCollection(TimeSpan.FromMilliseconds(250));adapter.TryAdd(42);adapter.TryTake(outvarvalue);

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

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages