Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/FSharp.Control.AsyncSeq/AsyncSeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@
member x.For (seq:AsyncSeq<'T>, action:'T -> AsyncSeq<'TResult>) =
collect action seq

member x.YieldFrom (s:seq<'T>) =
ofSeq s

let unfoldAsync (f:'State -> Async<('T * 'State) option>) (s:'State) : AsyncSeq<'T> =
new UnfoldAsyncEnumerator<_, _>(f, s) :> _

Expand Down Expand Up @@ -2017,7 +2020,7 @@

[<CompilerMessage("The result of groupBy must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.", 9999)>]
let groupBy (p:'a -> 'k) (s:AsyncSeq<'a>) : AsyncSeq<'k * AsyncSeq<'a>> =
groupByAsync (p >> async.Return) s

Check warning on line 2023 in src/FSharp.Control.AsyncSeq/AsyncSeq.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupByAsync must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.

Check warning on line 2023 in src/FSharp.Control.AsyncSeq/AsyncSeq.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupByAsync must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
#endif
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/FSharp.Control.AsyncSeq/AsyncSeq.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ module AsyncSeq =
/// Implements "yield!" for the asyncSeq computation builder.
member YieldFrom : source:AsyncSeq<'T> -> AsyncSeq<'T>

/// Implements "yield!" for a synchronous sequence in the asyncSeq computation builder.
member YieldFrom : source:seq<'T> -> AsyncSeq<'T>

/// Implements empty for the asyncSeq computation builder.
member Zero : unit -> AsyncSeq<'T>

Expand Down
20 changes: 20 additions & 0 deletions tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@
Assert.True(([1;2;3] = a))


[<Test>]
let ``asyncSeq yield! seq works``() =
let items = seq { 1; 2; 3 }
let s = asyncSeq {
yield! items
}
let a = s |> AsyncSeq.toListSynchronously
Assert.True(([1;2;3] = a))

[<Test>]
let ``asyncSeq yield! seq combines with other yields``() =
let items = seq { 2; 3 }
let s = asyncSeq {
yield 1
yield! items
yield 4
}
let a = s |> AsyncSeq.toListSynchronously
Assert.True(([1;2;3;4] = a))

[<Test>]
let ``AsyncSeq.concatSeq works``() =
let ls = [ [1;2] ; [3;4] ]
Expand Down Expand Up @@ -1830,7 +1850,7 @@
let actual =
ls
|> AsyncSeq.ofSeq
|> AsyncSeq.groupBy p

Check warning on line 1853 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupBy must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (snd >> AsyncSeq.toListAsync)
Assert.AreEqual(expected, actual)

Expand All @@ -1839,7 +1859,7 @@
let expected = asyncSeq { raise (exn("test")) }
let actual =
asyncSeq { raise (exn("test")) }
|> AsyncSeq.groupBy (fun i -> i % 3)

Check warning on line 1862 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupBy must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (snd >> AsyncSeq.toListAsync)
Assert.AreEqual(expected, actual)

Expand Down