dotnet / dotnet/fsharp

ignore keyword giving unexpected results

Open
#15,880 8 comments 0 reactions 0 assignees View on GitHub
Analyzers
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

**Repro steps**

```fsharp
open System.Threading.Channels
open FSharp.Control

let channel = Channel.CreateUnbounded();

let puts = task {
return! 0 |> channel.Writer.WriteAsync
return! 1 |> channel.Writer.WriteAsync
}

puts |> Async.AwaitTask |> Async.RunSynchronously |> ignore

channel.Writer.Complete |> ignore

channel.Reader.ReadAllAsync()
|> AsyncSeq.ofAsyncEnum
|> AsyncSeq.iter (fun x -> printfn "%i" x)
|> Async.RunSynchronously
|> ignore

"Done" |> System.Console.WriteLine |> ignore;
```
**Expected behavior**
The `IAsyncEnumerable` returned by `ReadAllAsync()` should behave like a finite set of 2 elements and come to an end.

**Actual behavior**
The `IAsyncEnumerable` never ends. "Done" is never written to the stdout. The `Channel` _isn't_ marked as `closed`.

**Workaround**
Swapping to `channel.Writer.Complete()` will cause this code to terminate.

I am new to F#, so this might be my ignorance, but my understanding is that `Complete()` and `Complete |> ignore` should be equivalent in this case. The only odd thing about `channel.Writer.Complete`, that I can see, is that it takes an optional parameter. Have I missed something obvious here? I couldn't find any mention of this type of behaviour while everything I've read suggests that `|> ignore` is the correct, idiomatic syntax.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.