{"id":16838926,"url":"https://github.com/akarnokd/async-enumerable-dotnet","last_synced_at":"2025-03-22T05:30:49.862Z","repository":{"id":33195468,"uuid":"153935493","full_name":"akarnokd/async-enumerable-dotnet","owner":"akarnokd","description":"Experimental operators for C# 8 IAsyncEnumerables","archived":false,"fork":false,"pushed_at":"2023-06-26T09:58:24.000Z","size":410,"stargazers_count":38,"open_issues_count":2,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-18T07:42:07.010Z","etag":null,"topics":["async","async-await","async-enumerable","concurrency","csharp"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akarnokd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-20T18:24:31.000Z","updated_at":"2024-06-19T10:00:55.711Z","dependencies_parsed_at":"2024-06-19T10:10:50.070Z","dependency_job_id":null,"html_url":"https://github.com/akarnokd/async-enumerable-dotnet","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarnokd%2Fasync-enumerable-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarnokd%2Fasync-enumerable-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarnokd%2Fasync-enumerable-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarnokd%2Fasync-enumerable-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akarnokd","download_url":"https://codeload.github.com/akarnokd/async-enumerable-dotnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244912800,"owners_count":20530764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","async-enumerable","concurrency","csharp"],"created_at":"2024-10-13T12:27:33.155Z","updated_at":"2025-03-22T05:30:47.417Z","avatar_url":"https://github.com/akarnokd.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-enumerable-dotnet\n\nExperimental operators for C# 8 [`IAsyncEnumerable`s](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=dotnet-plat-ext-3.0).\n\nTravis-CI: \u003ca href='https://travis-ci.com/akarnokd/async-enumerable-dotnet/builds'\u003e\u003cimg src='https://travis-ci.com/akarnokd/async-enumerable-dotnet.svg?branch=master' alt=\"async-enumerable-dotnet\"\u003e\u003c/a\u003e\nNuGet: \u003ca href='https://www.nuget.org/packages/akarnokd.async-enumerable-dotnet'\u003e\u003cimg src='https://img.shields.io/nuget/v/akarnokd.async-enumerable-dotnet.svg' alt=\"async-enumerable-dotnet\"/\u003e\u003c/a\u003e\n\n# Getting started\n\nNamespace: `async_enumerable_dotnet`\n\nFactory/Extension methods: `AsyncEnumerable`\n\nRequires: .NET Core 3 or later\n\n```cs\nusing async_enumerable_dotnet;\nusing System.Collections.Generic;\n\nvar result = AsyncEnumerable.Range(1, 10)\n    .Filter(v =\u003e v % 2 == 0)\n    .Map(v =\u003e v * 2)\n    .Take(5)\n    ;\n\nvar enumerator = result.GetAsyncEnumerator();\n\ntry\n{\n    while (await enumerator.MoveNextAsync()) \n    {\n        Console.WriteLine(enumerator.Current);\n    }\n\tConsole.WriteLine(\"Done\");\n}\nfinally\n{\n    await enumerator.DisposeAsync();\n}\n```\n\n## Available sources\n\n- `Amb` - Relay items of the source that responds first, disposing the others\n- `Create` - generate values via async push\n- `CombineLatest` - combines the latest items of the source async sequences via a function into results\n- `Concat` - concatenate multiple async sequences\n- `ConcatEager` - run multiple async sequences at once but relay elements in order similar to `Concat`\n- `Defer` - defer the creation of the actual `IAsyncEnumerable`\n- `Error` - signal an error\n- `Empty` - the async sequence ends without any values\n- `FromArray` - emit the items of an array\n- `FromEnumerable` - emit the items of an `IEnumerable`\n- `FromTask` - emit the value returned by an async task\n- `FromObservable` - convert an `IObservable` into an `IAsyncEnumerable`\n- `Interval` - periodically signal an ever increasing number\n- `Just` - emit a single constant value\n- `Merge` - run multiple sources at once and merge their items into a single async sequence\n- `Never` - the async sequence never produces any items and never terminates\n- `Range` - emit a range of numbers\n- `Switch` - switch between inner async sources produced by an outer async sequence\n- `Timer` - emit zero after some time delay\n- `Using` - use a resource for the duration of a generated actual `IAsyncEnumerable`\n- `Zip` - combine the next values of multiple sources via a function and emit its results\n\n## Intermediate operators\n\n- `Any` - signals true if any of the source items matched a predicate\n- `All` - signals true if all of the source items matched a predicate\n- `Buffer` - collect some number of items into buffer(s) and emit those buffers\n- `Collect` - collect items into a custom collection and emit the collection at the end\n- `ConcatMap` - concatenate in order the inner async sequences mapped from the main sequence\n- `ConcatMapEager` - run the async sources at once but relay elements in order similar to `ConcatMap`\n- `ConcatWith` - concatenate in order with another async sequence\n- `Count` - count the number of items in the async sequence\n- `Distinct` - makes sure only distinct elements get relayed\n- `DistinctUntilChanged` - relays an element only if it is distinct from the previous item\n- `Debounce` - wait a bit after each item and emit them if no newer item arrived from the source\n- `DefaultIfEmpty` - return a fallback value if the source async sequence turns out to be empty\n- `DoOnNext` - execute an action when an item becomes available\n- `DoOnDispose` - execute an action when the async sequence gets disposed.\n- `ElementAt` - get the element at a specified index or an error/default value\n- `Filter` - prevent items from passing through which don't pass a predicate\n- `First` - signals the first item of the async sequence\n- `FlatMap` - map the source items into `IAsyncEnumerable`s and merge their values into a single async sequence\n- `GroupBy` - groups the source elements into distinct async groups\n- `IgnoreElements` - ignores items and ends when the source async sequence ends\n- `IsEmpty` - signals a single true if the source is empty\n- `Last` - signals the last item of the async sequence\n- `Latest` - runs the source async sequence as fast as it can and samples it with the frequency of the consumer\n- `Map` - transform one source value into some other value\n- `MergeWith` - run two async sources at once and merge their items into a single async sequence\n- `OnErrorResumeNext` - if the main source fails, switch to an alternative source\n- `Prefetch` - run the source async sequence to prefetch items for a slow consumer\n- `Publish` - consume an async sequence once while multicasting its items to intermediate consumers for the duration of a function.\n- `Reduce` - combine elements with an accumulator and emit the last result\n- `Repeat` - repeatedly consume the entire source async sequence (up to a number of times and/or condition)\n- `Replay` - consume an async sequence once, caching some or all of its items and multicasting them to intermediate consumers for the duration of a function.\n- `Retry` - retry a failed async sequence (up to a number of times or based on condition)\n- `Sample` - periodically take the latest item from the source sequence and emit it\n- `Scan` - perform rolling aggregation by emitting intermediate results\n- `Single` - signals the only item of the async sequence, fails if the sequence has more than one item\n- `Skip` - skip the first specified number of items of the source async sequence\n- `SkipLast` - skip the last number of elements\n- `SkipUntil` - skip until another async sequence signals an item or completes\n- `SkipWhile` - skip items while the predicate returns true, start emitting when it turns false\n- `SwitchIfEmpty` - switch to an alternate async sequence if the main sequence turns out to be empty\n- `SwitchMap` - switch to a newer mapped-in async sequence, disposing the old one, whenever the source produces an item\n- `Take` - take at most a given number of items and stop the async sequence after that\n- `TakeLast` - take the last given number of items of the source async sequence and emit those\n- `TakeUntil` - take items from the main source until a secondary async sequence signals an item or completes\n- `TakeWhile` - take items while predicate is true and stop when it turns false\n- `Timeout` - signal an error if the next item doesn't arrive within the specified time\n- `ToList` - collects all items into a List and signals it as the single result of the async sequence\n- `WithLatestFrom` - combines the elements of the main sequence with the latest value(s) from other sequence(s)\n\n## End-consumers\n\n- `Consume` - consume the async sequence via a awaitable push interface of `IAsyncConsumer`\n- `FirstAsync` - get the very first value of the async sequence\n- `ForEach` - invoke callbacks for each item and for the terminal signals\n- `LastAsync` - get the very last value of the sequence\n- `SingleAsync` - get the only value of the sequence or signal error\n- `ToArrayAsync` - get all items as an array\n- `ToEnumerable` - convert the `IAsyncEnumerable` into a blocking `IEnumerable`\n- `ToListAsync` - get all items in an IList\n- `ToObservable` - convert the `IAsyncEnumerable` into an `IObservable`\n\n## Push-pull bridges\n\n- `MulticastAsyncEnumerable` - signals events to currently associated IAsyncEnumerator consumers (aka PublishSubject).\n- `ReplayAsyncEnumerable` - replays some or all items to its IAsyncEnumerator consumers (aka ReplaySubject).\n- `UnicastAsyncEnumerable` - buffers then replay items for an only consumer\n\n## Other components\n\n- `TestTaskRunner` - a class that creates tasks (of value, error or cancellation) that signal when a virtual time is moved forward (aka TestScheduler)\n\n### IAsyncConsumer\n\nRepresents a push-like consumer where items, an error and/or completion can be signaled and awaited:\n\n```cs\npublic interface IAsyncConsumer\u003cin T\u003e\n{\n    ValueTask Next(T item);\n\n    ValueTask Error(Exception error);\n\n    ValueTask Complete();\n}\n```\n\nThe methods must be awaited and called non-concurrently and non-overlappingly with themselves and each other:\n\n```\nNext* (Error | Complete)?\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarnokd%2Fasync-enumerable-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakarnokd%2Fasync-enumerable-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarnokd%2Fasync-enumerable-dotnet/lists"}