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

Task.Delay(0) => Task.CompletedTask #3049

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
2 changes: 1 addition & 1 deletion src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async Task<IResult> ExecuteCallback(ICommandContext context, object[] args, ISer
await instance.BeforeExecuteAsync(cmd).ConfigureAwait(false);
instance.BeforeExecute(cmd);

var task = method.Invoke(instance, args) as Task ?? Task.Delay(0);
var task = method.Invoke(instance, args) as Task ?? Task.CompletedTask;
if (task is Task<RuntimeResult> resultTask)
{
return await resultTask.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.Core/Audio/AudioStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Clear()
ClearAsync(CancellationToken.None).GetAwaiter().GetResult();
}

public virtual Task ClearAsync(CancellationToken cancellationToken) { return Task.Delay(0); }
public virtual Task ClearAsync(CancellationToken cancellationToken) { return Task.CompletedTask; }

/// <inheritdoc />
/// <exception cref="NotSupportedException">Reading stream length is not supported.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task GetMessagesExampleBody(IMessageChannel channel)
// Another dummy method
Task LongRunningAsync()
{
return Task.Delay(0);
return Task.CompletedTask;
}

#region GetMessagesAsync.FromLimit.Standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ async Task<IResult> ExecuteCallback(IInteractionContext context, object[] args,
{
await instance.BeforeExecuteAsync(commandInfo).ConfigureAwait(false);
instance.BeforeExecute(commandInfo);
var task = commandInvoker(instance, args) ?? Task.Delay(0);
var task = commandInvoker(instance, args) ?? Task.CompletedTask;

if (task is Task<RuntimeResult> runtimeTask)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Discord.Net.Rest/BaseDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal virtual async Task LoginInternalAsync(TokenType tokenType, string token
await _loggedInEvent.InvokeAsync().ConfigureAwait(false);
}
internal virtual Task OnLoginAsync(TokenType tokenType, string token)
=> Task.Delay(0);
=> Task.CompletedTask;

public async Task LogoutAsync()
{
Expand All @@ -150,7 +150,7 @@ internal virtual async Task LogoutInternalAsync()
await _loggedOutEvent.InvokeAsync().ConfigureAwait(false);
}
internal virtual Task OnLogoutAsync()
=> Task.Delay(0);
=> Task.CompletedTask;

internal virtual void Dispose(bool disposing)
{
Expand Down Expand Up @@ -266,10 +266,10 @@ Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.BulkOverwriteGloba

/// <inheritdoc />
Task IDiscordClient.StartAsync()
=> Task.Delay(0);
=> Task.CompletedTask;
/// <inheritdoc />
Task IDiscordClient.StopAsync()
=> Task.Delay(0);
=> Task.CompletedTask;

/// <summary>
/// Creates a test entitlement to a given SKU for a given guild or user.
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ private async Task LogoutInternalAsync()
LoginState = LoginState.LoggedOut;
}

internal virtual Task ConnectInternalAsync() => Task.Delay(0);
internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.Delay(0);
internal virtual Task ConnectInternalAsync() => Task.CompletedTask;
internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.CompletedTask;
#endregion

#region Core
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/DiscordRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal void CreateRestSelfUser(API.User user)
internal override Task OnLogoutAsync()
{
_applicationInfo = null;
return Task.Delay(0);
return Task.CompletedTask;
}

#region Rest interactions
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal virtual void Update(Model model)
}

/// <inheritdoc />
public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0);
public virtual Task UpdateAsync(RequestOptions options = null) => Task.CompletedTask;
#endregion

#region IChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public override Task ClearAsync(CancellationToken cancelToken)
do
cancelToken.ThrowIfCancellationRequested();
while (_queuedFrames.TryDequeue(out _));
return Task.Delay(0);
return Task.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/Audio/Streams/InputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
if (_signal.CurrentCount >= MaxFrames) //1-2 seconds
{
_hasHeader = false;
return Task.Delay(0); //Buffer overloaded
return Task.CompletedTask; //Buffer overloaded
}
if (!_hasHeader)
throw new InvalidOperationException("Received payload without an RTP header");
Expand All @@ -91,7 +91,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
payload: payload
));
_signal.Release();
return Task.Delay(0);
return Task.CompletedTask;
}

protected override void Dispose(bool isDisposing)
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/Audio/Streams/JitterBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override Task ClearAsync(CancellationToken cancelToken)
do
cancelToken.ThrowIfCancellationRequested();
while (_queuedFrames.TryDequeue(out Frame ignored));
return Task.Delay(0);
return Task.CompletedTask;
}
}
}*/
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/DiscordShardedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
//Should only happen if token is changed
var _ = LogoutAsync(); //Signal the logout, fire and forget
}
return Task.Delay(0);
return Task.CompletedTask;
};

client.SentRequest += (method, endpoint, millis) => _sentRequest.InvokeAsync(method, endpoint, millis);
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClie
{
var _ = g.DownloadUsersAsync();
}
return Task.Delay(0);
return Task.CompletedTask;
};

_largeGuilds = new ConcurrentQueue<ulong>();
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ internal async Task<IAudioClient> ConnectAudioAsync(ulong channelId, bool selfDe
audioClient.Connected += () =>
{
_ = promise.TrySetResultAsync(_audioClient);
return Task.Delay(0);
return Task.CompletedTask;
};

_audioClient = audioClient;
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task StopInternalAsync(bool isDisposing = false)
catch { }

if (!isDisposing)
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
await (_task ?? Task.CompletedTask).ConfigureAwait(false);

if (_udp != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposin

try
{
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
_task = null;
}
finally { _isDisconnecting = false; }
Expand Down
2 changes: 1 addition & 1 deletion test/Discord.Net.Tests.Unit/TypeReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string
public sealed class TestModule : ModuleBase
{
[Command("test")]
public Task TestCommand(ArgumentType arg) => Task.Delay(0);
public Task TestCommand(ArgumentType arg) => Task.CompletedTask;
}
}
Loading