Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Nov 22, 2023
1 parent 1b1f326 commit 5e8984a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ AsyncEx is similar to Async except in the following ways:
}
```
4. Use [IAsyncEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=net-8.0) with `for` keyword. This example uses [TaskSeq](https://github.com/fsprojects/FSharp.Control.TaskSeq) but you can use any `IAsyncEnumerable<T>`.
```fsharp
open IcedTasks
open FSharp.Control
let myAsyncEx = asyncEx {
let items = taskSeq { // IAsyncEnumerable<T>
yield 42
do! Task.Delay(100)
yield 1701
}
let mutable sum = 0
for i in items do
sum <- sum + i
return sum
}
```
### For [ValueTasks](https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/)
Expand Down
19 changes: 19 additions & 0 deletions docsSrc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ AsyncEx is similar to Async except in the following ways:
}
```
4. Use [IAsyncEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=net-8.0) with `for` keyword. This example uses [TaskSeq](https://github.com/fsprojects/FSharp.Control.TaskSeq) but you can use any `IAsyncEnumerable<T>`.
```fsharp
open IcedTasks
open FSharp.Control
let myAsyncEx = asyncEx {
let items = taskSeq { // IAsyncEnumerable<T>
yield 42
do! Task.Delay(100)
yield 1701
}
let mutable sum = 0
for i in items do
sum <- sum + i
return sum
}
```
### For [ValueTasks](https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/)
Expand All @@ -110,6 +128,7 @@ let myValueTask = task {
- You want to be able to re-run these executable tasks
- You don't want to pollute your methods/functions with extra CancellationToken parameters
- You want the computation to handle checking cancellation before every bind.
- You want to use the `for` keyword with `IAsyncEnumerable<T>`.


### ColdTask
Expand Down
2 changes: 2 additions & 0 deletions src/IcedTasks/AsyncEx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ module AsyncExExtensionsLowPriority =
/// <item><description>Allows <c>use</c> on <see cref="T:System.IAsyncDisposable">System.IAsyncDisposable</see></description></item>
/// <item><description>Allows <c>let!</c> for Tasks, ValueTasks, and any Awaitable Type</description></item>
/// <item><description>When Tasks throw exceptions they will use the behavior described in <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see></description></item>
/// <item><description>Allow <c>for</c> on <see cref="T:System.Collections.Generic.IAsyncEnumerable`1">System.Collections.Generic.IAsyncDisposable</see></description></item>
/// </list>
///
/// </remarks>
Expand Down Expand Up @@ -441,6 +442,7 @@ module PolyfillBuilders =
/// <item><description>Allows <c>use</c> on <see cref="T:System.IAsyncDisposable">System.IAsyncDisposable</see></description></item>
/// <item><description>Allows <c>let!</c> for Tasks, ValueTasks, and any Awaitable Type</description></item>
/// <item><description>When Tasks throw exceptions they will use the behavior described in <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see></description></item>
/// <item><description>Allow <c>for</c> on <see cref="T:System.Collections.Generic.IAsyncEnumerable`1">System.Collections.Generic.IAsyncDisposable</see></description></item>
/// </list>
///
/// </remarks>
Expand Down
13 changes: 11 additions & 2 deletions tests/IcedTasks.Tests/AsyncExTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open System.Collections.Generic


module AsyncExTests =
open FSharp.Control

let builderTests =
testList "AsyncExBuilder" [
Expand Down Expand Up @@ -678,8 +679,16 @@ module AsyncExTests =
Expect.equal actual index "Should be ok"
}
)


let foo = asyncEx {

Check failure on line 682 in tests/IcedTasks.Tests/AsyncExTests.fs

View workflow job for this annotation

GitHub Actions / build (Debug, windows-latest)

The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result.

Check failure on line 682 in tests/IcedTasks.Tests/AsyncExTests.fs

View workflow job for this annotation

GitHub Actions / build (Release, windows-latest)

The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result.
let items = taskSeq { // IAsyncEnumerable<T>
yield 42
do! Task.Yield()
yield 1701
}
let mutable sum = 0
for i in items do
sum <- sum + i
}
#if TEST_NETSTANDARD2_1 || TEST_NET6_0_OR_GREATER
yield!
[
Expand Down

0 comments on commit 5e8984a

Please sign in to comment.