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

Replace Task.FromResult by Task.CompletedTask #3162

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 2 additions & 6 deletions Microsoft.Toolkit.Uwp/Deferred/EventHandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -16,8 +14,6 @@ namespace Microsoft.Toolkit.Uwp.Deferred
/// </summary>
public static class EventHandlerExtensions
{
private static readonly Task CompletedTask = Task.FromResult(0);

/// <summary>
/// Use to invoke an async <see cref="EventHandler{TEventArgs}"/> using <see cref="DeferredEventArgs"/>.
/// </summary>
Expand Down Expand Up @@ -46,7 +42,7 @@ public static Task InvokeAsync<T>(this EventHandler<T> eventHandler, object send
{
if (eventHandler == null)
{
return CompletedTask;
return Task.CompletedTask;
}

var tasks = eventHandler.GetInvocationList()
Expand All @@ -59,7 +55,7 @@ public static Task InvokeAsync<T>(this EventHandler<T> eventHandler, object send

var deferral = eventArgs.GetCurrentDeferralAndReset();

return deferral?.WaitForCompletion(cancellationToken) ?? CompletedTask;
return deferral?.WaitForCompletion(cancellationToken) ?? Task.CompletedTask;
})
.ToArray();

Expand Down
6 changes: 2 additions & 4 deletions Microsoft.Toolkit.Uwp/Deferred/TypedEventHandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Microsoft.Toolkit.Uwp.Deferred
/// </summary>
public static class TypedEventHandlerExtensions
{
private static readonly Task CompletedTask = Task.FromResult(0);

/// <summary>
/// Use to invoke an async <see cref="TypedEventHandler{TSender, TResult}"/> using <see cref="DeferredEventArgs"/>.
/// </summary>
Expand Down Expand Up @@ -47,7 +45,7 @@ public static Task InvokeAsync<S, R>(this TypedEventHandler<S, R> eventHandler,
{
if (eventHandler == null)
{
return CompletedTask;
return Task.CompletedTask;
}

var tasks = eventHandler.GetInvocationList()
Expand All @@ -60,7 +58,7 @@ public static Task InvokeAsync<S, R>(this TypedEventHandler<S, R> eventHandler,

var deferral = eventArgs.GetCurrentDeferralAndReset();

return deferral?.WaitForCompletion(cancellationToken) ?? CompletedTask;
return deferral?.WaitForCompletion(cancellationToken) ?? Task.CompletedTask;
})
.ToArray();

Expand Down