Task.Delay(0) => Task.CompletedTask (#3049)
This commit is contained in:
@@ -211,7 +211,7 @@ namespace Discord.Commands
|
|||||||
await instance.BeforeExecuteAsync(cmd).ConfigureAwait(false);
|
await instance.BeforeExecuteAsync(cmd).ConfigureAwait(false);
|
||||||
instance.BeforeExecute(cmd);
|
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)
|
if (task is Task<RuntimeResult> resultTask)
|
||||||
{
|
{
|
||||||
return await resultTask.ConfigureAwait(false);
|
return await resultTask.ConfigureAwait(false);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Discord.Audio
|
|||||||
ClearAsync(CancellationToken.None).GetAwaiter().GetResult();
|
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 />
|
/// <inheritdoc />
|
||||||
/// <exception cref="NotSupportedException">Reading stream length is not supported.</exception>
|
/// <exception cref="NotSupportedException">Reading stream length is not supported.</exception>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Discord.Net.Examples.Core.Entities.Channels
|
|||||||
// Another dummy method
|
// Another dummy method
|
||||||
Task LongRunningAsync()
|
Task LongRunningAsync()
|
||||||
{
|
{
|
||||||
return Task.Delay(0);
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region GetMessagesAsync.FromLimit.Standard
|
#region GetMessagesAsync.FromLimit.Standard
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ namespace Discord.Interactions.Builders
|
|||||||
{
|
{
|
||||||
await instance.BeforeExecuteAsync(commandInfo).ConfigureAwait(false);
|
await instance.BeforeExecuteAsync(commandInfo).ConfigureAwait(false);
|
||||||
instance.BeforeExecute(commandInfo);
|
instance.BeforeExecute(commandInfo);
|
||||||
var task = commandInvoker(instance, args) ?? Task.Delay(0);
|
var task = commandInvoker(instance, args) ?? Task.CompletedTask;
|
||||||
|
|
||||||
if (task is Task<RuntimeResult> runtimeTask)
|
if (task is Task<RuntimeResult> runtimeTask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ namespace Discord.Rest
|
|||||||
await _loggedInEvent.InvokeAsync().ConfigureAwait(false);
|
await _loggedInEvent.InvokeAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
internal virtual Task OnLoginAsync(TokenType tokenType, string token)
|
internal virtual Task OnLoginAsync(TokenType tokenType, string token)
|
||||||
=> Task.Delay(0);
|
=> Task.CompletedTask;
|
||||||
|
|
||||||
public async Task LogoutAsync()
|
public async Task LogoutAsync()
|
||||||
{
|
{
|
||||||
@@ -150,7 +150,7 @@ namespace Discord.Rest
|
|||||||
await _loggedOutEvent.InvokeAsync().ConfigureAwait(false);
|
await _loggedOutEvent.InvokeAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
internal virtual Task OnLogoutAsync()
|
internal virtual Task OnLogoutAsync()
|
||||||
=> Task.Delay(0);
|
=> Task.CompletedTask;
|
||||||
|
|
||||||
internal virtual void Dispose(bool disposing)
|
internal virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
@@ -266,10 +266,10 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task IDiscordClient.StartAsync()
|
Task IDiscordClient.StartAsync()
|
||||||
=> Task.Delay(0);
|
=> Task.CompletedTask;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Task IDiscordClient.StopAsync()
|
Task IDiscordClient.StopAsync()
|
||||||
=> Task.Delay(0);
|
=> Task.CompletedTask;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a test entitlement to a given SKU for a given guild or user.
|
/// Creates a test entitlement to a given SKU for a given guild or user.
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ namespace Discord.API
|
|||||||
LoginState = LoginState.LoggedOut;
|
LoginState = LoginState.LoggedOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual Task ConnectInternalAsync() => Task.Delay(0);
|
internal virtual Task ConnectInternalAsync() => Task.CompletedTask;
|
||||||
internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.Delay(0);
|
internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.CompletedTask;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Core
|
#region Core
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace Discord.Rest
|
|||||||
internal override Task OnLogoutAsync()
|
internal override Task OnLogoutAsync()
|
||||||
{
|
{
|
||||||
_applicationInfo = null;
|
_applicationInfo = null;
|
||||||
return Task.Delay(0);
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Rest interactions
|
#region Rest interactions
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace Discord.Rest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0);
|
public virtual Task UpdateAsync(RequestOptions options = null) => Task.CompletedTask;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IChannel
|
#region IChannel
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ namespace Discord.Audio.Streams
|
|||||||
do
|
do
|
||||||
cancelToken.ThrowIfCancellationRequested();
|
cancelToken.ThrowIfCancellationRequested();
|
||||||
while (_queuedFrames.TryDequeue(out _));
|
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
|
if (_signal.CurrentCount >= MaxFrames) //1-2 seconds
|
||||||
{
|
{
|
||||||
_hasHeader = false;
|
_hasHeader = false;
|
||||||
return Task.Delay(0); //Buffer overloaded
|
return Task.CompletedTask; //Buffer overloaded
|
||||||
}
|
}
|
||||||
if (!_hasHeader)
|
if (!_hasHeader)
|
||||||
throw new InvalidOperationException("Received payload without an RTP header");
|
throw new InvalidOperationException("Received payload without an RTP header");
|
||||||
@@ -91,7 +91,7 @@ namespace Discord.Audio.Streams
|
|||||||
payload: payload
|
payload: payload
|
||||||
));
|
));
|
||||||
_signal.Release();
|
_signal.Release();
|
||||||
return Task.Delay(0);
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ namespace Discord.Audio.Streams
|
|||||||
do
|
do
|
||||||
cancelToken.ThrowIfCancellationRequested();
|
cancelToken.ThrowIfCancellationRequested();
|
||||||
while (_queuedFrames.TryDequeue(out Frame ignored));
|
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
|
//Should only happen if token is changed
|
||||||
var _ = LogoutAsync(); //Signal the logout, fire and forget
|
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);
|
client.SentRequest += (method, endpoint, millis) => _sentRequest.InvokeAsync(method, endpoint, millis);
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
var _ = g.DownloadUsersAsync();
|
var _ = g.DownloadUsersAsync();
|
||||||
}
|
}
|
||||||
return Task.Delay(0);
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_largeGuilds = new ConcurrentQueue<ulong>();
|
_largeGuilds = new ConcurrentQueue<ulong>();
|
||||||
|
|||||||
@@ -1793,7 +1793,7 @@ namespace Discord.WebSocket
|
|||||||
audioClient.Connected += () =>
|
audioClient.Connected += () =>
|
||||||
{
|
{
|
||||||
_ = promise.TrySetResultAsync(_audioClient);
|
_ = promise.TrySetResultAsync(_audioClient);
|
||||||
return Task.Delay(0);
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
_audioClient = audioClient;
|
_audioClient = audioClient;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace Discord.Net.Udp
|
|||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
if (!isDisposing)
|
if (!isDisposing)
|
||||||
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
|
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
|
||||||
|
|
||||||
if (_udp != null)
|
if (_udp != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ namespace Discord.Net.WebSockets
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await (_task ?? Task.Delay(0)).ConfigureAwait(false);
|
await (_task ?? Task.CompletedTask).ConfigureAwait(false);
|
||||||
_task = null;
|
_task = null;
|
||||||
}
|
}
|
||||||
finally { _isDisconnecting = false; }
|
finally { _isDisconnecting = false; }
|
||||||
|
|||||||
@@ -137,6 +137,6 @@ namespace Discord
|
|||||||
public sealed class TestModule : ModuleBase
|
public sealed class TestModule : ModuleBase
|
||||||
{
|
{
|
||||||
[Command("test")]
|
[Command("test")]
|
||||||
public Task TestCommand(ArgumentType arg) => Task.Delay(0);
|
public Task TestCommand(ArgumentType arg) => Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user