-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IAsyncEnumerable support to TransformManyBlock #49264
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: Issue DetailsContributes to #30863
|
8fb929f
to
47bb2d9
Compare
Tagging @eiriktsarpalis as he might be interested in reviewing this. |
Tagging @adamsitnik, @carlossanlop, and @jozkee for reviewing this. |
Pinging @adamsitnik, @carlossanlop, and @jozkee for a review on this. |
47bb2d9
to
a9f0f80
Compare
@adamsitnik This PR is assigned to you for follow-up/decision before the RC1 snap. |
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
...raries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.IAsyncEnumerable.cs
Show resolved
Hide resolved
{ | ||
// Validate arguments. | ||
if (transform == null) throw new ArgumentNullException(nameof(transform)); | ||
Initialize(messageId => ProcessMessageWithTask(transform, messageId), dataflowBlockOptions, ref _source!, ref _target!, ref _reorderingBuffer, async: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the benefits of changing private ctor
to a method? You need to pass few more extra args, take references and use !
to pretend that fields which are nulls are not nulls. I don't like this part of the refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an attempt to solve an issue reported by @stephentoub during a previous review in #37876 (comment)
To duplicate code or not to duplicate code... that is the question!
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
@stephentoub could you please review this PR as well? I don't feel confident signing off |
@manandre The PR description says "contributes to" instead of "fixes". Does that mean there will still be some pending work to address after you merge this, or is this the last PR to fully address the issue? |
Yes. I need to set aside some time for it... I'm still a bit hesitant around all the code duplication. |
It should be the last PR to complete the IAsyncEnumerable support in Dataflow. |
FWIW I've tried to wrap my head around the additional duplication and the only idea I had was to use map Pseudocode: private async IAsyncEnumerable<TOutput> Map(Task<IEnumerable<TOutput>> oldWay)
{
foreach (TOutput item in await oldWay.ConfigureAwait(false))
{
yield return item;
}
} The obvious disadvantage would be the perf hit, but the real blocker is that DataFlow targets monikers like Based on #30863 (comment) I've moved it to 7.0. |
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/System.Threading.Tasks.Dataflow.csproj
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
@manandre any thoughts on the code duplication issue pointed out by @adamsitnik and @stephentoub? |
29606e9
to
08d0312
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manandre Let us know if you'd be able to try the approach @stephentoub described. Thanks!
If we want to implement the
I am still ready to contribute for the full support of |
Normally we would if-def the target platforms, but i guess that would cause again a code dup which we want to avoid, @joperezr mentioned we could not drop those TFMs, what we should do here @stephentoub?
From the SslStream implementation that abstracting sync over async read and write that @stephentoub metnioned above doesn't require everything to be async for a real, for example: runtime/src/libraries/System.Net.Security/src/System/Net/Security/ReadWriteAdapter.cs Lines 52 to 59 in ce15dc7
For me that really depend on implementation and not have to inroduce perf regression, @manandre have you tried it and got some perf results? |
This pull request has been automatically marked |
This is still on me to spend some time on and try to come up with a better approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I just added a few small code style notes and I would like to see some comments on the test flow so that the tests can be understood when roughly reading over them.
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs
Show resolved
Hide resolved
...raries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Outdated
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
...s/System.Threading.Tasks.Dataflow/tests/Dataflow/TransformManyBlockTests.IAsyncEnumerable.cs
Show resolved
Hide resolved
This pull request has been automatically marked |
08d0312
to
8da7858
Compare
@stephentoub Whats the current status of this? |
@deeprobin, why are you asking about status on this PR? |
Because I have planned to look at the DataFlow APIs in a private project and would like to consume this API. |
My plan is for it to be in .NET 7. |
8da7858
to
18aa3de
Compare
Over the last few weeks I experimented with various approaches, but there's enough variation between the three @manandre, thank you very much for working on this, and thank you for your patience. |
Contributes to #30863
cc @onionhammer @stephentoub