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

This commit is contained in:
Mihail Gribkov
2025-01-08 20:20:49 +03:00
committed by GitHub
parent 35e812253a
commit b5f5df0fde
17 changed files with 22 additions and 22 deletions

View File

@@ -211,7 +211,7 @@ namespace Discord.Commands
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);

View File

@@ -27,7 +27,7 @@ namespace Discord.Audio
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>

View File

@@ -49,7 +49,7 @@ namespace Discord.Net.Examples.Core.Entities.Channels
// Another dummy method
Task LongRunningAsync()
{
return Task.Delay(0);
return Task.CompletedTask;
}
#region GetMessagesAsync.FromLimit.Standard

View File

@@ -425,7 +425,7 @@ namespace Discord.Interactions.Builders
{
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)
{

View File

@@ -124,7 +124,7 @@ namespace Discord.Rest
await _loggedInEvent.InvokeAsync().ConfigureAwait(false);
}
internal virtual Task OnLoginAsync(TokenType tokenType, string token)
=> Task.Delay(0);
=> Task.CompletedTask;
public async Task LogoutAsync()
{
@@ -150,7 +150,7 @@ namespace Discord.Rest
await _loggedOutEvent.InvokeAsync().ConfigureAwait(false);
}
internal virtual Task OnLogoutAsync()
=> Task.Delay(0);
=> Task.CompletedTask;
internal virtual void Dispose(bool disposing)
{
@@ -266,10 +266,10 @@ namespace Discord.Rest
/// <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.

View File

@@ -195,8 +195,8 @@ namespace Discord.API
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

View File

@@ -85,7 +85,7 @@ namespace Discord.Rest
internal override Task OnLogoutAsync()
{
_applicationInfo = null;
return Task.Delay(0);
return Task.CompletedTask;
}
#region Rest interactions

View File

@@ -79,7 +79,7 @@ namespace Discord.Rest
}
/// <inheritdoc />
public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0);
public virtual Task UpdateAsync(RequestOptions options = null) => Task.CompletedTask;
#endregion
#region IChannel

View File

@@ -187,7 +187,7 @@ namespace Discord.Audio.Streams
do
cancelToken.ThrowIfCancellationRequested();
while (_queuedFrames.TryDequeue(out _));
return Task.Delay(0);
return Task.CompletedTask;
}
}
}

View File

@@ -76,7 +76,7 @@ namespace Discord.Audio.Streams
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");
@@ -91,7 +91,7 @@ namespace Discord.Audio.Streams
payload: payload
));
_signal.Release();
return Task.Delay(0);
return Task.CompletedTask;
}
protected override void Dispose(bool isDisposing)

View File

@@ -240,7 +240,7 @@ namespace Discord.Audio.Streams
do
cancelToken.ThrowIfCancellationRequested();
while (_queuedFrames.TryDequeue(out Frame ignored));
return Task.Delay(0);
return Task.CompletedTask;
}
}
}*/

View File

@@ -428,7 +428,7 @@ namespace Discord.WebSocket
//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);

View File

@@ -200,7 +200,7 @@ namespace Discord.WebSocket
{
var _ = g.DownloadUsersAsync();
}
return Task.Delay(0);
return Task.CompletedTask;
};
_largeGuilds = new ConcurrentQueue<ulong>();

View File

@@ -1793,7 +1793,7 @@ namespace Discord.WebSocket
audioClient.Connected += () =>
{
_ = promise.TrySetResultAsync(_audioClient);
return Task.Delay(0);
return Task.CompletedTask;
};
_audioClient = audioClient;

View File

@@ -92,7 +92,7 @@ namespace Discord.Net.Udp
catch { }
if (!isDisposing)
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
if (_udp != null)
{

View File

@@ -140,7 +140,7 @@ namespace Discord.Net.WebSockets
try
{
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
_task = null;
}
finally { _isDisconnecting = false; }

View File

@@ -137,6 +137,6 @@ namespace Discord
public sealed class TestModule : ModuleBase
{
[Command("test")]
public Task TestCommand(ArgumentType arg) => Task.Delay(0);
public Task TestCommand(ArgumentType arg) => Task.CompletedTask;
}
}