Giter Site home page Giter Site logo

asyncenumerableextensions's Introduction

CXuesong.AsyncEnumerableExtensions | NuGet version (CXuesong.AsyncEnumerableExtensions) NuGet version (CXuesong.AsyncEnumerableExtensions)

AsyncEnumerableExtensions

As of May, 2019, there is IAsyncEnumerable on .NET Standard 2.1 / .NET Core 3.0. Thus this package uses built-in IAsyncEnumerable instead of the one in Ix.Async on these supporting platform. Note that on .NET Standard 1.1, this package will still target to Ix.Async.

Building your asynchronous sequence, i.e. IAsyncEnumerable<T> implementation with asynchronous generator methods! This helper package let you write one generator function, and it's compatible with both .NET Standard 1.1 and .NET Standard 2.1.

[Fact]
public async void NormalGeneratorTest()
{
    var finished = false;
    async Task Generator(IAsyncEnumerableSink<int> sink)
    {
        // Yield some items.
        await sink.YieldAndWait(10);
        await sink.YieldAndWait(20);
        // Do some work.
        await Task.Delay(100);
        // Yield some more items.
        await sink.YieldAndWait(new[] {30, 40});
        // Ditto.
        await Task.Delay(100);
        await sink.YieldAndWait(50);
        finished = true;
    }

    // Replace ToArray with ToArrayAsync on .NET Core 3.0 / .NET Standard 2.1
    var array = await AsyncEnumerableFactory.FromAsyncGenerator<int>(Generator).ToArray();
    Assert.True(finished);
    Assert.Equal(new[] {10, 20, 30, 40, 50}, array);
}

For more usage examples, including cancellation support, see UnitTestProject1/UnitTest1.cs.

Use this package with .NET Core 3.0 Preview

When consuming this package with .NET Core 3.0 Preview, be sure to install the System.Linq.Async NuGet package with version higher than 4.0.0-preview.6.build.801, or you may see the following error during run time when calling certain extension methods like ToList.

  Error Message:
   System.MissingMethodException : Method not found: 'System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1<System.__Canon> System.Threading.Tasks.TaskExtensions.WithCancellation(System.Collections.Generic.IAsyncEnumerable`1<System.__Canon>, System.Threading.CancellationToken)'.
  Stack Trace:
     at System.Linq.AsyncEnumerable.<ToListAsync>g__Core|620_0[TSource](IAsyncEnumerable`1 _source, CancellationToken _cancellationToken) in d:\a\1\s\Ix.NET\Source\System.Linq.Async\System\Linq\Operators\ToList.cs:line 25
     …

asyncenumerableextensions's People

Contributors

cxuesong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jangocheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.