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
> NOTE: There is also the option to use [FSharp.Control.TaskSeq](https://github.com/fsprojects/FSharp.Control.TaskSeq) which has a very similar usage model.
30
+
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.
21
31
22
-
An AsyncSeq is a sequence in which individual elements are retrieved using an `Async` computation.
23
-
It is similar to `seq<'a>` in that subsequent elements are pulled on-demand.
24
-
`AsyncSeq` also bears similarity to `IObservable<'a>` with the former being based on an "asynchronous pull" and the
25
-
latter based on a "synchronous push". Analogs for most operations defined for `Seq`, `List` and `IObservable` are also defined for
26
-
`AsyncSeq`. The power of `AsyncSeq` lies in that many of these operations also have analogs based on `Async`
27
-
allowing composition of complex asynchronous workflows.
32
+
The `FSharp.Control.AsyncSeq` library is an implementation of functional asynchronous sequences for F#. The central type of the library is `AsyncSeq<'T>` and is a type alias for `System.Collections.Generic.IAsyncEnumerable<'T>`.
28
33
29
-
> **v4.0 and later:**`AsyncSeq<'T>` is a type alias for `System.Collections.Generic.IAsyncEnumerable<'T>`.
30
-
> Any `IAsyncEnumerable<'T>` value (e.g. from EF Core, ASP.NET Core channels, or `taskSeq { }`) can be used
31
-
> directly as an `AsyncSeq<'T>` without conversion, and vice-versa.
34
+
This library was also [one of the world's first implementations of asynchronous sequences](http://tomasp.net/blog/async-sequences.aspx) and has been used in production for many years. It is a mature library with a rich set of operations defined on `AsyncSeq` and is widely used in the F# community.
32
35
33
-
The `AsyncSeq` type is located in the `FSharp.Control.AsyncSeq.dll` assembly which can be loaded in F# Interactive as follows:
36
+
To use the library, referrence the NuGet package `FSharp.Control.AsyncSeq` in your project and open the `FSharp.Control` namespace:
34
37
*)
35
38
36
-
#r "../../../bin/FSharp.Control.AsyncSeq.dll"
37
39
openFSharp.Control
38
40
39
41
(**
40
42
### Generating asynchronous sequences
41
43
42
-
An `AsyncSeq<'T>`can be generated using computation expression syntax much like `seq<'T>`:
44
+
An asynchronous sequence can be generated using a computation expression, much like `seq<'T>`:
43
45
*)
44
46
45
47
letasync12= asyncSeq {
46
48
yield1
47
49
yield2
48
50
}
49
51
52
+
(**
53
+
or more succinctly:
54
+
*)
55
+
56
+
letasync12b= asyncSeq {1;2}
57
+
50
58
(**
51
59
Another way to generate an asynchronous sequence is using the `Async.unfoldAsync` function. This
52
60
function accepts as an argument a function which can generate individual elements based on a state and
0 commit comments