-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Akka.Streams: Have SelectAsyncUnordered use local async function instead of ContinueWith
#7531
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,7 @@ await this.AssertAllStagesStoppedAsync(async() => { | |
| .To(Sink.FromSubscriber(c)).Run(Materializer); | ||
| var sub = await c.ExpectSubscriptionAsync(); | ||
| sub.Request(10); | ||
| c.ExpectError().InnerException.Message.Should().Be("err1"); | ||
| (await c.ExpectErrorAsync()).Message.Should().Be("err1"); | ||
| latch.CountDown(); | ||
| }, Materializer); | ||
| } | ||
|
|
@@ -193,7 +193,7 @@ await this.AssertAllStagesStoppedAsync(async() => { | |
| .RunWith(Sink.FromSubscriber(c), Materializer); | ||
| var sub = await c.ExpectSubscriptionAsync(); | ||
| sub.Request(10); | ||
| c.ExpectError().Message.Should().Be("err2"); | ||
| (await c.ExpectErrorAsync()).Message.Should().Be("err2"); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer get |
||
| latch.CountDown(); | ||
| }, Materializer); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2808,7 +2808,7 @@ private sealed class Logic : InAndOutGraphStageLogic | |
| public Logic(Attributes inheritedAttributes, SelectAsyncUnordered<TIn, TOut> stage) : base(stage.Shape) | ||
| { | ||
| _stage = stage; | ||
| var attr = inheritedAttributes.GetAttribute<ActorAttributes.SupervisionStrategy>(null); | ||
| var attr = inheritedAttributes.GetAttribute<ActorAttributes.SupervisionStrategy>(); | ||
| _decider = attr != null ? attr.Decider : Deciders.StoppingDecider; | ||
|
|
||
| _taskCallback = GetAsyncCallback<Result<TOut>>(TaskCompleted); | ||
|
|
@@ -2827,8 +2827,10 @@ public override void OnPush() | |
| if (task.IsCompleted) | ||
| TaskCompleted(Result.FromTask(task)); | ||
| else | ||
| task.ContinueWith(t => _taskCallback(Result.FromTask(t)), | ||
| TaskContinuationOptions.ExecuteSynchronously); | ||
| { | ||
| // use an async local function to await the task and then run the task callback | ||
| _ = RunTask(task); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
|
|
@@ -2838,6 +2840,20 @@ public override void OnPush() | |
|
|
||
| if (Todo < _stage._parallelism && !HasBeenPulled(_stage.In)) | ||
| TryPull(_stage.In); | ||
| return; | ||
|
|
||
| async Task RunTask(Task<TOut> tt) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use an Replicates the same work we did on #7521 |
||
| { | ||
| try | ||
| { | ||
| var result = Result.Success(await tt); | ||
| _taskCallback(result); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _taskCallback(Result.Failure<TOut>(ex)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public override void OnUpstreamFinish() | ||
|
|
@@ -2909,42 +2925,22 @@ private int Todo | |
|
|
||
| private readonly int _parallelism; | ||
| private readonly Func<TIn, Task<TOut>> _mapFunc; | ||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
|
|
||
| public readonly Inlet<TIn> In = new("SelectAsyncUnordered.in"); | ||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
| public readonly Outlet<TOut> Out = new("SelectAsyncUnordered.out"); | ||
|
|
||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
| /// <param name="parallelism">TBD</param> | ||
| /// <param name="mapFunc">TBD</param> | ||
| public readonly Outlet<TOut> Out = new("SelectAsyncUnordered.out"); | ||
|
|
||
| public SelectAsyncUnordered(int parallelism, Func<TIn, Task<TOut>> mapFunc) | ||
| { | ||
| _parallelism = parallelism; | ||
| _mapFunc = mapFunc; | ||
| Shape = new FlowShape<TIn, TOut>(In, Out); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
|
|
||
| protected override Attributes InitialAttributes { get; } = Attributes.CreateName("selectAsyncUnordered"); | ||
|
|
||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
|
|
||
| public override FlowShape<TIn, TOut> Shape { get; } | ||
|
|
||
| /// <summary> | ||
| /// TBD | ||
| /// </summary> | ||
| /// <param name="inheritedAttributes">TBD</param> | ||
| /// <returns>TBD</returns> | ||
|
|
||
| protected override GraphStageLogic CreateLogic(Attributes inheritedAttributes) | ||
| => new Logic(inheritedAttributes, this); | ||
| } | ||
|
|
||
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.
We no longer get
AggregateExceptions here unless the test completes immediately, in which case we might have to harden this in the future.