You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An asynchronous sequence is a sequence in which individual elements are _awaited_, so the next element of the sequence is not necessarily available immediately. This allows for efficient composition of asynchronous workflows which involve sequences of data.
31
-
32
-
FSharp.Control.AsyncSeq is an implementation of functional-first programming over asynchronous sequences for F#. The central type of the library, `AsyncSeq<'T>`, is a type alias for the standard type `System.Collections.Generic.IAsyncEnumerable<'T>`.
33
-
34
-
This library was also [one of the world's first implementations of langauge integrated asynchronous sequences](http://tomasp.net/blog/async-sequences.aspx) - that is, asynchronous sequences with integrated language support through computation expressions. It is a mature library used in production for many years and is widely used in the F# community.
35
-
36
-
### Generating asynchronous sequences
30
+
## Generating asynchronous sequences
37
31
38
32
To use the library, referrence the NuGet package `FSharp.Control.AsyncSeq` in your project and open the `FSharp.Control` namespace:
39
33
*)
@@ -56,19 +50,6 @@ or more succinctly:
56
50
letasync12b= asyncSeq {1;2}
57
51
58
52
(**
59
-
### Comparison with `FSharp.Control.TaskSeq`
60
-
61
-
A related library is [`FSharp.Control.TaskSeq`](https://github.com/fsprojects/FSharp.Control.TaskSeq/) which provides a similar API for sequences of `Task<'T>` instead of `Async<'T>`. The two libraries are very similar and the choice between them is mostly a matter of preference or performance. The `AsyncSeq` library integrates well with the F# `Async` type, while the `TaskSeq` library is more performant and integrates well with the .NET `Task` type.
62
-
63
-
Both libraries implement that .NET standard `IAsyncEnumerable<'T>` interface, so they can be used interchangeably in most scenarios.
64
-
65
-
### Comparison with seq<'T>
66
-
67
-
The central difference between `seq<'T>` and `AsyncSeq<'T>` can be illustrated by introducing the notion of time.
68
-
Suppose that generating subsequent elements of a sequence requires an IO-bound operation. Invoking long
69
-
running IO-bound operations from within a `seq<'T>` will *block* the thread which calls `MoveNext` on the
70
-
corresponding `IEnumerator`. An `AsyncSeq` on the other hand can use facilities provided by the F# `Async` type to make
71
-
more efficient use of system resources.
72
53
*)
73
54
74
55
openSystem.Threading
@@ -88,18 +69,14 @@ let withTime2 = asyncSeq {
88
69
}
89
70
90
71
(**
91
-
When the asynchronous sequence `withTime'` is iterated, the calls to `Async.Sleep` won't block threads. Instead,
92
-
the *continuation* of the sequence will be scheduled by `Async` while the calling thread will be free to perform other work.
93
-
Overall, a `seq<'a>` can be viewed as a special case of an `AsyncSeq<'a>` where subsequent elements are retrieved
94
-
in a blocking manner.
95
-
96
-
### Performance Considerations
97
-
98
-
While an asynchronous computation obviates the need to block an OS thread for the duration of an operation, it isn't always the case
99
-
that this will improve the overall performance of an application. Note however that an async computation does not *require* a
100
-
non-blocking operation, it simply allows for it. Also of note is that unlike calling `IEnumerable.MoveNext()`, consuming
101
-
an item from an asynchronous sequence requires several allocations. Usually this is greatly outweighed by the
102
-
benefits, it can make a difference in some scenarios.
72
+
When the asynchronous sequence `withTime'` is iterated, the calls to `Async.Sleep` won't block threads. Instead, the *continuation* of the sequence will be scheduled by `Async` while the calling thread will be free to perform other work. Overall, a `seq<'a>` can be viewed as a special case of an `AsyncSeq<'a>` where subsequent elements are retrieved in a blocking manner.
73
+
74
+
*)
75
+
76
+
(**
77
+
## Performance Considerations
78
+
79
+
While an asynchronous computation obviates the need to block an OS thread for the duration of an operation, it isn't always the case that this will improve the overall performance of an application. Note however that an async computation does not *require* a non-blocking operation, it simply allows for it. Also of note is that unlike calling `IEnumerable.MoveNext()`, consuming an item from an asynchronous sequence requires several allocations. Usually this is greatly outweighed by the benefits, it can make a difference in some scenarios.
FSharp.Control.AsyncSeq is a collection of asynchronous programming utilities for F#.
5
4
6
-
An `AsyncSeq<'T>` is a sequence in which individual elements are retrieved using an `Async` computation.
7
-
The power of `AsyncSeq` lies in that many of these operations also have analogs based on `Async`
8
-
allowing composition of complex asynchronous workflows, including compositional cancellation.
5
+
An asynchronous sequence is a sequence in which individual elements are _awaited_, so the next element of the sequence is not necessarily available immediately. This allows for efficient composition of asynchronous workflows which involve sequences of data.
9
6
10
-
> **v4.0:**`AsyncSeq<'T>` is now a type alias for `System.Collections.Generic.IAsyncEnumerable<'T>`.
11
-
> Values flow freely between `AsyncSeq<'T>` and `IAsyncEnumerable<'T>` without any conversion.
12
-
> `AsyncSeq.ofAsyncEnum` / `AsyncSeq.toAsyncEnum` are now no-ops and marked obsolete — remove them.
13
-
> See the [README](https://github.com/fsprojects/FSharp.Control.AsyncSeq#version-40--bcl-iasyncenumerable-compatibility) for migration notes.
7
+
FSharp.Control.AsyncSeq is an implementation of functional-first programming over asynchronous sequences for F#. The central type of the library, `AsyncSeq<'T>`, is a type alias for the standard type `System.Collections.Generic.IAsyncEnumerable<'T>`.
8
+
9
+
This was [one of the world's first implementations of langauge integrated asynchronous sequences](http://tomasp.net/blog/async-sequences.aspx) - that is, asynchronous sequences with integrated language support through computation expressions. It is a mature library used in production for many years and is widely used in the F# community.
14
10
15
11
An `AsyncSeq<'a>` can be generated using computation expression syntax much like `seq<'a>`:
16
12
@@ -20,34 +16,26 @@ An `AsyncSeq<'a>` can be generated using computation expression syntax much like
20
16
yield 2
21
17
}
22
18
23
-
Learning
24
-
--------------------------
19
+
## Learning
20
+
21
+
*[Tutorial](AsyncSeq.fsx).
22
+
*[Generating sequences](AsyncSeqGenerating.fsx)
23
+
*[Transforming and reducing sequences](AsyncSeqTransforming.fsx)
24
+
*[Combining sequences](AsyncSeqCombining.fsx)
25
+
*[Advanced topics](AsyncSeqAdvanced.fsx)
25
26
26
-
[AsyncSeq](AsyncSeq.html) contains narrative and code samples explaining asynchronous sequences.
[Terminology](terminology.html) a reference for some of the terminology around F# async.
31
-
32
-
[Comparison with IObservable](ComparisonWithIObservable.html) contains discussion about the difference between async sequences and IObservables.
31
+
[`FSharp.Control.TaskSeq`](https://github.com/fsprojects/FSharp.Control.TaskSeq/) provides a similar API oriented towards `Task<'T>` instead of `Async<'T>`. The choice between them is mostly a matter of preference or performance. The `AsyncSeq` library integrates well with the F# `Async<_>` type, while the `TaskSeq` library is more performant and integrates well with the .NET `Task<_>` type.
33
32
34
-
[API Reference](reference/index.html) contains automatically generated documentation for all types, modules and functions in the library.
35
-
This includes additional brief samples on using most of the functions.
33
+
Both libraries implement that .NET standard `IAsyncEnumerable<'T>` interface, so they can be used interchangeably in most scenarios.
36
34
37
-
Contributing and copyright
38
-
--------------------------
35
+
### seq<'T>
39
36
40
-
The project is hosted on [GitHub][gh] where you can [report issues][issues], fork
41
-
the project and submit pull requests. If you're adding a new public API, please also
42
-
consider adding [samples][content] that can be turned into a documentation. You might
43
-
also want to read the [library design notes][readme] to understand how it works.
37
+
The central difference between `seq<'T>` and `AsyncSeq<'T>` can be illustrated by introducing the notion of time. Suppose that generating subsequent elements of a sequence requires an IO-bound operation. Invoking long running IO-bound operations from within a `seq<'T>` will _block_ the thread which calls `MoveNext` on the corresponding `IEnumerator`. An `AsyncSeq` on the other hand can use facilities provided by the F# `Async` type to make more efficient use of system resources.
44
38
45
-
The library is available under Apache 2.0 license, which allows modification and
46
-
redistribution for both commercial and non-commercial purposes. For more information see the
0 commit comments