Skip to content
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

Optimize PipeTo ConfigureAwait call #5688

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/core/Akka/Actor/PipeToSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Task PipeTo<T>(
IActorRef sender = null,
Func<T, object> success = null,
Func<Exception, object> failure = null)
=> PipeTo(taskToPipe, recipient, true, sender, success, failure);
=> PipeTo(taskToPipe, recipient, false, sender, success, failure);

/// <summary>
/// Pipes the output of a Task directly to the <paramref name="recipient"/>'s mailbox once
Expand All @@ -46,7 +46,7 @@ public static Task PipeTo<T>(
/// <param name="sender">The IActorRef that will be used as the sender of the result. Defaults to <see cref="ActorRefs.Nobody"/> </param>
/// <param name="success">A callback function that will be called on Task success. Defaults to <c>null</c> for no callback</param>
/// <param name="failure">A callback function that will be called on Task failure. Defaults to <c>null</c> for no callback</param>
/// <param name="useConfigureAwait">If set to true, <c>taskToPipe</c> will be awaited using <c>ConfigureAwait(false)</c></param>
/// <param name="useConfigureAwait">Sets the <c>taskToPipe.ConfigureAwait(bool)</c> <c>bool</c> parameter</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/// <returns>A detached task</returns>
public static async Task PipeTo<T>(
this Task<T> taskToPipe,
Expand All @@ -60,9 +60,7 @@ public static async Task PipeTo<T>(

try
{
var result = useConfigureAwait
? await taskToPipe.ConfigureAwait(false)
: await taskToPipe;
var result = await taskToPipe.ConfigureAwait(useConfigureAwait);

recipient.Tell(success != null
? success(result)
Expand Down Expand Up @@ -92,7 +90,7 @@ public static Task PipeTo(
IActorRef sender = null,
Func<object> success = null,
Func<Exception, object> failure = null)
=> PipeTo(taskToPipe, recipient, true, sender, success, failure);
=> PipeTo(taskToPipe, recipient, false, sender, success, failure);

/// <summary>
/// Pipes the output of a Task directly to the <paramref name="recipient"/>'s mailbox once
Expand All @@ -103,7 +101,7 @@ public static Task PipeTo(
/// <param name="sender">The IActorRef that will be used as the sender of the result. Defaults to <see cref="ActorRefs.Nobody"/> </param>
/// <param name="success">A callback function that will be called on Task success. Defaults to <c>null</c> for no callback</param>
/// <param name="failure">A callback function that will be called on Task failure. Defaults to <c>null</c> for no callback</param>
/// <param name="useConfigureAwait">If set to true, <c>taskToPipe</c> will be awaited using <c>ConfigureAwait(false)</c></param>
/// <param name="useConfigureAwait">Sets the <c>taskToPipe.ConfigureAwait(bool)</c> <c>bool</c> parameter</param>
/// <returns>A detached task</returns>
public static async Task PipeTo(
this Task taskToPipe,
Expand All @@ -117,14 +115,7 @@ public static async Task PipeTo(

try
{
if (useConfigureAwait)
{
await taskToPipe.ConfigureAwait(false);
}
else
{
await taskToPipe;
}
await taskToPipe.ConfigureAwait(useConfigureAwait);

if (success != null)
{
Expand Down