dotnet / dotnet/reactive

AsyncEnumerableEx.Merge doesn't behave the same in all cases

Open
#1,284 4 comments 0 reactions 0 assignees View on GitHub
[area] Ix
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

I think I found a bug, or at least behavior that I wasn't expecting. I'm using `AsyncEnumerableEx.Merge` to try and parallelize a few `IAsyncEnumerable`s. For testing, I'm using this method:

```
static async IAsyncEnumerable Foo(string prefix)
{
var rng = new Random();
Console.WriteLine(prefix);
await Task.Delay(rng.Next(1000, 5000));
yield return $"{prefix} 1";
await Task.Delay(rng.Next(1000, 5000));
yield return $"{prefix} 2";
await Task.Delay(rng.Next(1000, 5000));
yield return $"{prefix} 3";
}
```

When I run it with this:

`return AsyncEnumerableEx.Merge(Foo("a"), Foo("b"), Foo("c"));`

I get the expected output, ordered "a b c" console lines, followed by mixed prefix lines.

However, when I run it with this:

`return AsyncEnumerableEx.Merge(new List { "a", "b", "c" }.Select(x => Foo(x)));`

It blocks, I get a and its prefix lines, then b and its prefix lines, and c then its prefix lines.

I would have expected, perhaps incorrectly, both forms of the method to work the same way.

``

Using `ToList` after the `Select` doesn't seem to work either, but `ToArray` does.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.