Promise completions should be executed on the thread pool
This commit is contained in:
@@ -230,7 +230,7 @@ namespace Discord.Audio
|
|||||||
_secretKey = data.SecretKey;
|
_secretKey = data.SecretKey;
|
||||||
await ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
|
await ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
|
||||||
|
|
||||||
_connectTask.TrySetResult(true);
|
var _ = _connectTask.TrySetResultAsync(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VoiceOpCode.HeartbeatAck:
|
case VoiceOpCode.HeartbeatAck:
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ namespace Discord
|
|||||||
await _readyEvent.InvokeAsync().ConfigureAwait(false);
|
await _readyEvent.InvokeAsync().ConfigureAwait(false);
|
||||||
await SyncGuildsAsync().ConfigureAwait(false);
|
await SyncGuildsAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_connectTask.TrySetResult(true); //Signal the .Connect() call to complete
|
var _ = Task.Run(() => _connectTask.TrySetResult(true)); //Signal the .Connect() call to complete
|
||||||
await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false);
|
await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -96,9 +96,9 @@ namespace Discord
|
|||||||
AddUser(model.Members[i], dataStore, members);
|
AddUser(model.Members[i], dataStore, members);
|
||||||
if (Discord.ApiClient.AuthTokenType != TokenType.User)
|
if (Discord.ApiClient.AuthTokenType != TokenType.User)
|
||||||
{
|
{
|
||||||
_syncPromise.TrySetResult(true);
|
var _ = _syncPromise.TrySetResultAsync(true);
|
||||||
if (!model.Large)
|
if (!model.Large)
|
||||||
_downloaderPromise.TrySetResult(true);
|
_ = _downloaderPromise.TrySetResultAsync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < model.Presences.Length; i++)
|
for (int i = 0; i < model.Presences.Length; i++)
|
||||||
@@ -122,9 +122,9 @@ namespace Discord
|
|||||||
DownloadedMemberCount = 0;
|
DownloadedMemberCount = 0;
|
||||||
for (int i = 0; i < model.Members.Length; i++)
|
for (int i = 0; i < model.Members.Length; i++)
|
||||||
AddUser(model.Members[i], dataStore, members);
|
AddUser(model.Members[i], dataStore, members);
|
||||||
_syncPromise.TrySetResult(true);
|
var _ = _syncPromise.TrySetResultAsync(true);
|
||||||
if (!model.Large)
|
if (!model.Large)
|
||||||
_downloaderPromise.TrySetResult(true);
|
_ = _downloaderPromise.TrySetResultAsync(true);
|
||||||
|
|
||||||
for (int i = 0; i < model.Presences.Length; i++)
|
for (int i = 0; i < model.Presences.Length; i++)
|
||||||
AddOrUpdateUser(model.Presences[i], dataStore, members);
|
AddOrUpdateUser(model.Presences[i], dataStore, members);
|
||||||
@@ -233,7 +233,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
public void CompleteDownloadMembers()
|
public void CompleteDownloadMembers()
|
||||||
{
|
{
|
||||||
_downloaderPromise.TrySetResult(true);
|
_downloaderPromise.TrySetResultAsync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VoiceState AddOrUpdateVoiceState(VoiceStateModel model, DataStore dataStore, ConcurrentDictionary<ulong, VoiceState> voiceStates = null)
|
public VoiceState AddOrUpdateVoiceState(VoiceStateModel model, DataStore dataStore, ConcurrentDictionary<ulong, VoiceState> voiceStates = null)
|
||||||
|
|||||||
23
src/Discord.Net/Extensions/TaskCompletionSourceExtensions.cs
Normal file
23
src/Discord.Net/Extensions/TaskCompletionSourceExtensions.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Discord
|
||||||
|
{
|
||||||
|
internal static class TaskCompletionSourceExtensions
|
||||||
|
{
|
||||||
|
public static Task SetResultAsync<T>(this TaskCompletionSource<T> source, T result)
|
||||||
|
=> Task.Run(() => source.SetResult(result));
|
||||||
|
public static Task<bool> TrySetResultAsync<T>(this TaskCompletionSource<T> source, T result)
|
||||||
|
=> Task.Run(() => source.TrySetResult(result));
|
||||||
|
|
||||||
|
public static Task SetExceptionAsync<T>(this TaskCompletionSource<T> source, Exception ex)
|
||||||
|
=> Task.Run(() => source.SetException(ex));
|
||||||
|
public static Task<bool> TrySetExceptionAsync<T>(this TaskCompletionSource<T> source, Exception ex)
|
||||||
|
=> Task.Run(() => source.TrySetException(ex));
|
||||||
|
|
||||||
|
public static Task SetCanceledAsync<T>(this TaskCompletionSource<T> source)
|
||||||
|
=> Task.Run(() => source.SetCanceled());
|
||||||
|
public static Task<bool> TrySetCanceledAsync<T>(this TaskCompletionSource<T> source)
|
||||||
|
=> Task.Run(() => source.TrySetCanceled());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -141,7 +141,7 @@ namespace Discord.Net.Queue
|
|||||||
private async Task QueueResumeAsync(TaskCompletionSource<byte> resumeNotifier, int millis)
|
private async Task QueueResumeAsync(TaskCompletionSource<byte> resumeNotifier, int millis)
|
||||||
{
|
{
|
||||||
await Task.Delay(millis).ConfigureAwait(false);
|
await Task.Delay(millis).ConfigureAwait(false);
|
||||||
resumeNotifier.SetResult(0);
|
resumeNotifier.TrySetResultAsync<byte>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EnterAsync(int? endTick)
|
private async Task EnterAsync(int? endTick)
|
||||||
|
|||||||
Reference in New Issue
Block a user