AsyncEnumerator 1.1.3

Introduces IAsyncEnumerable, IAsyncEnumerator, ForEachAsync(), and ParallelForEachAsync()


Helps to (a) create an element provider, where producing an element can take a lot of time
due to dependency on other asynchronous events (e.g. wait handles, network streams), and
(b) a consumer that processes those element as soon as they are ready without blocking
the thread (the processing is scheduled on a worker thread instead).


using System.Collections.Async;

static IAsyncEnumerable<int> ProduceAsyncNumbers(int start, int end)
 return new AsyncEnumerable<int>(async yield => {

   // Just to show that ReturnAsync can be used multiple times
   await yield.ReturnAsync(start);

   for (int number = start + 1; number <= end; number++)
     await yield.ReturnAsync(number);

   // You can break the enumeration loop with the following call:

   // This won't be executed due to the loop break above
   await yield.ReturnAsync(12345);

// Just to compare with synchronous version of enumerator
static IEnumerable<int> ProduceNumbers(int start, int end)
 yield return start;

 for (int number = start + 1; number <= end; number++)
   yield return number;

 yield break;

 yield return 12345;

static async Task ConsumeNumbersAsync()
 var asyncEnumerableCollection = ProduceAsyncNumbers(start: 1, end: 10);
 await asyncEnumerableCollection.ForEachAsync(async number => {
   await Console.Out.WriteLineAsync($"{number}");

// Just to compare with synchronous version of enumeration
static void ConsumeNumbers()
 // NOTE: IAsyncEnumerable is derived from IEnumerable, so you can use either
 var enumerableCollection = ProduceAsyncNumbers(start: 1, end: 10);
 //var enumerableCollection = ProduceNumbers(start: 1, end: 10);

 foreach (var number in enumerableCollection) {

There is a newer version of this package available.
See the version list below for details.
Install-Package AsyncEnumerator -Version 1.1.3
dotnet add package AsyncEnumerator --version 1.1.3
<PackageReference Include="AsyncEnumerator" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AsyncEnumerator --version 1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AsyncEnumerator, 1.1.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 AsyncEnumerator as a Cake Addin
#addin nuget:?package=AsyncEnumerator&version=1.1.3

// Install AsyncEnumerator as a Cake Tool
#tool nuget:?package=AsyncEnumerator&version=1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Release Notes

Add AsyncEnumerable.Empty and improve exception and cancellation handling in ParallelForEachAsync.


This package has no dependencies.

NuGet packages (28)

Showing the top 5 NuGet packages that depend on AsyncEnumerator:

Package Downloads
Library for querying data indexed by NBitcoin.Indexer on Azure Storage
.Net Core Utilities methods
A new small, happy, dynamic micro-ORM and general purpose .NET data access wrapper. Based on and highly compatible with Massive, but now with: * .NET Core 1.0+, 2.0+ and 3.0+ (with continuing support for .NET Framework 4.0+ and 4.5+) * Optional strong typing (with continuing full support for dynamic types) * Full stored procedure support * Parameter names and directions (where you need it; automatic parameter naming as in Massive still works just as before) * Full transaction support * Cursor support on Oracle and PostgreSQL (cursors are not designed to be passed out to client code on any other supported databases) * Multiple result sets * Simultaneous access to more then one database provider
Package Description
Package Description

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on AsyncEnumerator:

Repository Stars
Open source utility to manage Steam, Origin and Uplay libraries in ease of use with multi library support
Blockchain core in C#/.NET for persistent peer-to-peer online games
Every developer deserves the right of creating microservices without using any framework 🤍
Secure, Modern, Fully-Featured, All-In-One Cross-Architecture & Cross-Platform DNS Server Using C# 8.0 & .NET Core 3.1
Open Source ASP.NET Core Enterprise eCommerce Shopping Cart Solution

Version History

Version Downloads Last updated
4.0.2 1,256,025 12/4/2019
4.0.1 76,376 10/22/2019
4.0.0 8,250 10/18/2019
3.1.0 54,360 9/23/2019
2.2.2 1,087,759 1/27/2019
2.2.1 1,177,431 5/29/2018
2.2.0 25,541 5/18/2018
2.1.1 111,875 1/20/2018
2.1.0 227,611 5/22/2017
2.0.1 49,269 2/13/2017
1.5.0 3,650 2/12/2017
1.4.2 1,411 2/6/2017
1.3.0 1,675 1/20/2017
1.2.3 6,658 1/6/2017
1.2.2 1,908 12/11/2016
1.2.1 664 12/10/2016
1.2.0 18,519 11/29/2016
1.1.3 712 11/28/2016
1.1.2 42,117 8/29/2016
1.0.3 3,441 4/28/2016
Show less