Skip to content

Commit 648b9c6

Browse files
committed
Add TaskSeq vs AsyncSeq comparison table
1 parent 3de9efb commit 648b9c6

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ Latest version [can be installed from Nuget][nuget].
2424
- [`taskSeq` computation expressions](#taskseq-computation-expressions)
2525
- [Installation](#installation)
2626
- [Examples](#examples)
27-
- [Status & planning](#status--planning)
27+
- [Status \& planning](#status--planning)
2828
- [Implementation progress](#implementation-progress)
2929
- [Progress `taskSeq` CE](#progress-taskseq-ce)
3030
- [Progress and implemented `TaskSeq` module functions](#progress-and-implemented-taskseq-module-functions)
3131
- [More information](#more-information)
32-
- [Further reading `IAsyncEnumerable`](#further-reading-iasyncenumerable)
32+
- [The AsyncSeq library](#the-asyncseq-library)
33+
- [Further reading on `IAsyncEnumerable`](#further-reading-on-iasyncenumerable)
3334
- [Further reading on resumable state machines](#further-reading-on-resumable-state-machines)
3435
- [Further reading on computation expressions](#further-reading-on-computation-expressions)
35-
- [Building & testing](#building--testing)
36+
- [Building \& testing](#building--testing)
3637
- [Prerequisites](#prerequisites)
3738
- [Build the solution](#build-the-solution)
3839
- [Run the tests](#run-the-tests)
@@ -332,9 +333,29 @@ The following is the progress report:
332333

333334
### The AsyncSeq library
334335

335-
If you're looking to use `IAsyncEnumerable` with `async` and not `task`, the existing [`AsyncSeq`][11] library already provides excellent coverage of that use case. While `TaskSeq` is intended to interoperate with `async` as `task` does, it's not intended to provide an `AsyncSeq` type (at least not yet).
336-
337-
In short, if your application is using `Async` (and the parallelism features stemming from that), consider using the `AsyncSeq` library instead.
336+
The [`AsyncSeq`][11] and `TaskSeq` library both operate on asynchronous sequences, but there are a few fundamental differences, most notably that the former _does not_ implement `IAsyncEnumerable<'T>`, but has its own same-named, but differently behaving type.
337+
338+
There are more differences:
339+
340+
| | `TaskSeq` | `AsyncSeq` |
341+
|------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------------|
342+
| Frameworks | .NET 5.0+, NetStandard 2.1 | .NET 5.0+, NetStandard 2.0 and 2.1, .NET Framework 4.6.1+ |
343+
| Underlying type | `System.Collections.Generic.IAsyncEnumerable<'T> | Its own type, also called `IAsyncEnumerable<'T>`, but not compatible |
344+
| Implementation | State machine (statically compiled) | No state machine, continuation style |
345+
| Semantics | `seq`-like: on-demand | `seq`-like: on-demand |
346+
| Support `let!` | All task-like: `Async<'T>`, `task`, `ValueTask<'T>`, `Task<'T>` or `GetAwaiter()` | `Async<'T>` only |
347+
| Support `do!` | `Async<unit>`, `Task<unit>`, `Task`, `ValueTask<unit>`, `ValueTask` | `Async<unit>` only |
348+
| Support `yield!` | `IAsyncEnumerable<'T>`, `AsyncSeq`, any sequence | `AsyncSeq` |
349+
| Support `for` | `IAsyncEnumerable<'T>`, `AsyncSeq`, any sequence | `AsyncSeq` any sequence |
350+
| Conversion to other | `TaskSeq.toAsyncSeq` | `AsyncSeq.toAsyncEnum` |
351+
| Conversion from other | Implicit (yield!) or `TaskSeq.ofAsyncSeq` | `AsyncSeq.ofAsyncEnum` |
352+
| Recursion in `yield!` | No (requires F# support, upcoming) | Yes |
353+
| Based on F# concept of | `task` | `async` |
354+
| MoveNext operation | `ValueTask<bool>` | `Ascyn<'T option>` |
355+
| Cancellation | Implicit token governing iteration | Implicit token passed to each subtask |
356+
| Performance | Very high, negligible allocations | Slower, more allocations, due to using `async` |
357+
| Behavior with `Return` | No allocations, no `Task` created | Allocated, a `Task` will be created |
358+
| Parallelism | Possible with ChildTask, support will follow | Supported explicitly |
338359

339360
### Further reading on `IAsyncEnumerable`
340361

0 commit comments

Comments
 (0)