Task.Delay(0) => Task.CompletedTask (#3049)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Discord.Rest
|
||||
internal override Task OnLogoutAsync()
|
||||
{
|
||||
_applicationInfo = null;
|
||||
return Task.Delay(0);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#region Rest interactions
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace Discord.Audio.Streams
|
||||
do
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
while (_queuedFrames.TryDequeue(out _));
|
||||
return Task.Delay(0);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace Discord.Audio.Streams
|
||||
do
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
while (_queuedFrames.TryDequeue(out Frame ignored));
|
||||
return Task.Delay(0);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var _ = g.DownloadUsersAsync();
|
||||
}
|
||||
return Task.Delay(0);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_largeGuilds = new ConcurrentQueue<ulong>();
|
||||
|
||||
@@ -1793,7 +1793,7 @@ namespace Discord.WebSocket
|
||||
audioClient.Connected += () =>
|
||||
{
|
||||
_ = promise.TrySetResultAsync(_audioClient);
|
||||
return Task.Delay(0);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_audioClient = audioClient;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user