From cc723df6ad56d132269e773a73259ed092504649 Mon Sep 17 00:00:00 2001
From: Hsu Still <341464@gmail.com>
Date: Mon, 16 Apr 2018 03:07:56 +0800
Subject: [PATCH] Add ConfigureAwait(false) for most missing tasks
---
.../Preconditions/RequireOwnerAttribute.cs | 2 +-
.../Builders/ModuleClassBuilder.cs | 2 +-
src/Discord.Net.Commands/Info/CommandInfo.cs | 4 ++--
.../Readers/NullableTypeReader.cs | 2 +-
.../Readers/UserTypeReader.cs | 8 ++++---
src/Discord.Net.Core/Utils/Cacheable.cs | 4 ++--
src/Discord.Net.Rest/ClientHelper.cs | 2 +-
src/Discord.Net.Rest/DiscordRestApiClient.cs | 14 +++++------
src/Discord.Net.Rest/DiscordRestClient.cs | 4 ++--
.../Entities/Channels/RestTextChannel.cs | 6 ++---
.../Channels/RpcVirtualMessageChannel.cs | 23 +++++++++----------
.../Entities/Guilds/GuildHelper.cs | 8 +++----
.../Entities/Guilds/RestGuild.cs | 6 ++---
.../Entities/Messages/MessageHelper.cs | 2 +-
.../Entities/Users/RestUser.cs | 2 +-
.../Entities/Users/UserHelper.cs | 4 ++--
.../DiscordSocketClient.cs | 14 +++++------
.../Entities/Channels/SocketTextChannel.cs | 6 ++---
.../Entities/Webhooks/RestInternalWebhook.cs | 2 +-
.../WebhookClientHelper.cs | 2 +-
20 files changed, 59 insertions(+), 58 deletions(-)
diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
index 22f234384..21277d8b1 100644
--- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
+++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
@@ -15,7 +15,7 @@ namespace Discord.Commands
switch (context.Client.TokenType)
{
case TokenType.Bot:
- var application = await context.Client.GetApplicationInfoAsync();
+ var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false);
if (context.User.Id != application.Owner.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot.");
return PreconditionResult.FromSuccess();
diff --git a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
index 1dd66cc77..cbeb6bffd 100644
--- a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
+++ b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
@@ -34,7 +34,7 @@ namespace Discord.Commands
}
else if (IsLoadableModule(typeInfo))
{
- await service._cmdLogger.WarningAsync($"Class {typeInfo.FullName} is not public and cannot be loaded. To suppress this message, mark the class with {nameof(DontAutoLoadAttribute)}.");
+ await service._cmdLogger.WarningAsync($"Class {typeInfo.FullName} is not public and cannot be loaded. To suppress this message, mark the class with {nameof(DontAutoLoadAttribute)}.").ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs
index 213543cc4..e4dda456f 100644
--- a/src/Discord.Net.Commands/Info/CommandInfo.cs
+++ b/src/Discord.Net.Commands/Info/CommandInfo.cs
@@ -122,11 +122,11 @@ namespace Discord.Commands
return PreconditionGroupResult.FromSuccess();
}
- var moduleResult = await CheckGroups(Module.Preconditions, "Module");
+ var moduleResult = await CheckGroups(Module.Preconditions, "Module").ConfigureAwait(false);
if (!moduleResult.IsSuccess)
return moduleResult;
- var commandResult = await CheckGroups(Preconditions, "Command");
+ var commandResult = await CheckGroups(Preconditions, "Command").ConfigureAwait(false);
if (!commandResult.IsSuccess)
return commandResult;
diff --git a/src/Discord.Net.Commands/Readers/NullableTypeReader.cs b/src/Discord.Net.Commands/Readers/NullableTypeReader.cs
index 109689e15..1a64dc198 100644
--- a/src/Discord.Net.Commands/Readers/NullableTypeReader.cs
+++ b/src/Discord.Net.Commands/Readers/NullableTypeReader.cs
@@ -28,7 +28,7 @@ namespace Discord.Commands
{
if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase))
return TypeReaderResult.FromSuccess(new T?());
- return await _baseTypeReader.ReadAsync(context, input, services);
+ return await _baseTypeReader.ReadAsync(context, input, services).ConfigureAwait(false);
}
}
}
diff --git a/src/Discord.Net.Commands/Readers/UserTypeReader.cs b/src/Discord.Net.Commands/Readers/UserTypeReader.cs
index 92e516d43..7a9e177ff 100644
--- a/src/Discord.Net.Commands/Readers/UserTypeReader.cs
+++ b/src/Discord.Net.Commands/Readers/UserTypeReader.cs
@@ -45,7 +45,7 @@ namespace Discord.Commands
if (ushort.TryParse(input.Substring(index + 1), out ushort discriminator))
{
var channelUser = await channelUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator &&
- string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase));
+ string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase)).ConfigureAwait(false);
AddResult(results, channelUser as T, channelUser?.Username == username ? 0.85f : 0.75f);
var guildUser = guildUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator &&
@@ -58,7 +58,8 @@ namespace Discord.Commands
{
await channelUsers
.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase))
- .ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == input ? 0.65f : 0.55f));
+ .ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == input ? 0.65f : 0.55f))
+ .ConfigureAwait(false);
foreach (var guildUser in guildUsers.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase)))
AddResult(results, guildUser as T, guildUser.Username == input ? 0.60f : 0.50f);
@@ -68,7 +69,8 @@ namespace Discord.Commands
{
await channelUsers
.Where(x => string.Equals(input, (x as IGuildUser)?.Nickname, StringComparison.OrdinalIgnoreCase))
- .ForEachAsync(channelUser => AddResult(results, channelUser as T, (channelUser as IGuildUser).Nickname == input ? 0.65f : 0.55f));
+ .ForEachAsync(channelUser => AddResult(results, channelUser as T, (channelUser as IGuildUser).Nickname == input ? 0.65f : 0.55f))
+ .ConfigureAwait(false);
foreach (var guildUser in guildUsers.Where(x => string.Equals(input, (x as IGuildUser).Nickname, StringComparison.OrdinalIgnoreCase)))
AddResult(results, guildUser as T, (guildUser as IGuildUser).Nickname == input ? 0.60f : 0.50f);
diff --git a/src/Discord.Net.Core/Utils/Cacheable.cs b/src/Discord.Net.Core/Utils/Cacheable.cs
index c2d83b04d..f09e4d4cf 100644
--- a/src/Discord.Net.Core/Utils/Cacheable.cs
+++ b/src/Discord.Net.Core/Utils/Cacheable.cs
@@ -35,13 +35,13 @@ namespace Discord
/// Thrown when the message is deleted.
public async Task DownloadAsync()
{
- return await DownloadFunc();
+ return await DownloadFunc().ConfigureAwait(false);
}
/// Returns the cached entity if it exists; otherwise downloads it.
/// An awaitable Task containing a cached or downloaded entity.
/// Thrown when used from a user account.
/// Thrown when the message is deleted and is not in cache.
- public async Task GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync();
+ public async Task GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync().ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs
index 08305f857..73e1a08f0 100644
--- a/src/Discord.Net.Rest/ClientHelper.cs
+++ b/src/Discord.Net.Rest/ClientHelper.cs
@@ -146,7 +146,7 @@ namespace Discord.Rest
public static async Task GetWebhookAsync(BaseDiscordClient client, ulong id, RequestOptions options)
{
- var model = await client.ApiClient.GetWebhookAsync(id);
+ var model = await client.ApiClient.GetWebhookAsync(id).ConfigureAwait(false);
if (model != null)
return RestWebhook.Create(client, (IGuild)null, model);
return null;
diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs
index f0c4358ad..c8ff616e2 100644
--- a/src/Discord.Net.Rest/DiscordRestApiClient.cs
+++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs
@@ -401,7 +401,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- await SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
+ await SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false);
}
public async Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)
{
@@ -412,7 +412,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
+ await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false);
}
//Channel Messages
@@ -1078,7 +1078,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- return await SendAsync("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options);
+ return await SendAsync("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false);
}
public async Task CreateGuildEmoteAsync(ulong guildId, Rest.CreateGuildEmoteParams args, RequestOptions options = null)
@@ -1090,7 +1090,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- return await SendJsonAsync("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options);
+ return await SendJsonAsync("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options).ConfigureAwait(false);
}
public async Task ModifyGuildEmoteAsync(ulong guildId, ulong emoteId, ModifyGuildEmoteParams args, RequestOptions options = null)
@@ -1101,7 +1101,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options);
+ return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options).ConfigureAwait(false);
}
public async Task DeleteGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null)
@@ -1111,7 +1111,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(guildId: guildId);
- await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options);
+ await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false);
}
//Users
@@ -1211,7 +1211,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(channelId: channelId);
- return await SendJsonAsync("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options);
+ return await SendJsonAsync("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options).ConfigureAwait(false);
}
public async Task GetWebhookAsync(ulong webhookId, RequestOptions options = null)
{
diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs
index 8850da3a5..2dc3ebe05 100644
--- a/src/Discord.Net.Rest/DiscordRestClient.cs
+++ b/src/Discord.Net.Rest/DiscordRestClient.cs
@@ -37,7 +37,7 @@ namespace Discord.Rest
///
public async Task GetApplicationInfoAsync(RequestOptions options = null)
{
- return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options));
+ return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false));
}
///
@@ -165,6 +165,6 @@ namespace Discord.Rest
=> await GetVoiceRegionAsync(id, options).ConfigureAwait(false);
async Task IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options)
- => await GetWebhookAsync(id, options);
+ => await GetWebhookAsync(id, options).ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
index 600b197d6..9752697d6 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
@@ -88,11 +88,11 @@ namespace Discord.Rest
//ITextChannel
async Task ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options)
- => await CreateWebhookAsync(name, avatar, options);
+ => await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false);
async Task ITextChannel.GetWebhookAsync(ulong id, RequestOptions options)
- => await GetWebhookAsync(id, options);
+ => await GetWebhookAsync(id, options).ConfigureAwait(false);
async Task> ITextChannel.GetWebhooksAsync(RequestOptions options)
- => await GetWebhooksAsync(options);
+ => await GetWebhooksAsync(options).ConfigureAwait(false);
//IMessageChannel
async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
diff --git a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
index 3b6a68193..049f86c08 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
@@ -53,7 +53,7 @@ namespace Discord.Rest
async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
- return await GetMessageAsync(id, options);
+ return await GetMessageAsync(id, options).ConfigureAwait(false);
else
return null;
}
@@ -79,28 +79,27 @@ namespace Discord.Rest
return AsyncEnumerable.Empty>();
}
async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
- => await GetPinnedMessagesAsync(options);
+ => await GetPinnedMessagesAsync(options).ConfigureAwait(false);
#if FILESYSTEM
async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options)
- => await SendFileAsync(filePath, text, isTTS, embed, options);
+ => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
#endif
async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options)
- => await SendFileAsync(stream, filename, text, isTTS, embed, options);
+ => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
- => await SendMessageAsync(text, isTTS, embed, options);
+ => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);
//IChannel
- string IChannel.Name { get { throw new NotSupportedException(); } }
- IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
- {
+ string IChannel.Name =>
throw new NotSupportedException();
- }
- Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
- {
+
+ IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) =>
+ throw new NotSupportedException();
+
+ Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) =>
throw new NotSupportedException();
- }
}
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
index 12fdb075d..38c5fe9e2 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
@@ -237,7 +237,7 @@ namespace Discord.Rest
};
if (info.Position != null)
args.AfterUserId = info.Position.Value;
- var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
+ var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options).ConfigureAwait(false);
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
},
nextPage: (info, lastPage) =>
@@ -280,7 +280,7 @@ namespace Discord.Rest
//Emotes
public static async Task GetEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
{
- var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options);
+ var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false);
return emote.ToEntity();
}
public static async Task CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional> roles,
@@ -294,7 +294,7 @@ namespace Discord.Rest
if (roles.IsSpecified)
apiargs.RoleIds = roles.Value?.Select(xr => xr.Id)?.ToArray();
- var emote = await client.ApiClient.CreateGuildEmoteAsync(guild.Id, apiargs, options);
+ var emote = await client.ApiClient.CreateGuildEmoteAsync(guild.Id, apiargs, options).ConfigureAwait(false);
return emote.ToEntity();
}
public static async Task ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action func,
@@ -312,7 +312,7 @@ namespace Discord.Rest
if (props.Roles.IsSpecified)
apiargs.RoleIds = props.Roles.Value?.Select(xr => xr.Id)?.ToArray();
- var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options);
+ var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false);
return emote.ToEntity();
}
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
index 5d12731a6..15d106804 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
@@ -121,7 +121,7 @@ namespace Discord.Rest
public async Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null)
{
var arr = args.ToArray();
- await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options);
+ await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options).ConfigureAwait(false);
}
public async Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null)
{
@@ -420,8 +420,8 @@ namespace Discord.Rest
Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); }
async Task IGuild.GetWebhookAsync(ulong id, RequestOptions options)
- => await GetWebhookAsync(id, options);
+ => await GetWebhookAsync(id, options).ConfigureAwait(false);
async Task> IGuild.GetWebhooksAsync(RequestOptions options)
- => await GetWebhooksAsync(options);
+ => await GetWebhooksAsync(options).ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
index 8ae41cc37..071628da0 100644
--- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
@@ -43,7 +43,7 @@ namespace Discord.Rest
public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
{
- await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options);
+ await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
}
public static async Task> GetReactionUsersAsync(IMessage msg, IEmote emote,
diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs
index c484986b1..f0c771ae0 100644
--- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs
+++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs
@@ -68,6 +68,6 @@ namespace Discord.Rest
//IUser
async Task IUser.GetOrCreateDMChannelAsync(RequestOptions options)
- => await GetOrCreateDMChannelAsync(options);
+ => await GetOrCreateDMChannelAsync(options).ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs
index dfb81ff2c..3e7493ab5 100644
--- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs
@@ -76,13 +76,13 @@ namespace Discord.Rest
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options)
{
foreach (var role in roles)
- await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options);
+ await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
}
public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options)
{
foreach (var role in roles)
- await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options);
+ await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
}
}
}
diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
index 911666de4..80c16ea79 100644
--- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs
+++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
@@ -1146,7 +1146,7 @@ namespace Discord.WebSocket
after = SocketMessage.Create(this, State, author, channel, data);
}
- var cacheableBefore = new Cacheable(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id));
+ var cacheableBefore = new Cacheable(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id).ConfigureAwait(false));
await TimedInvokeAsync(_messageUpdatedEvent, nameof(MessageUpdated), cacheableBefore, after, channel).ConfigureAwait(false);
}
@@ -1193,9 +1193,9 @@ namespace Discord.WebSocket
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
- var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
+ var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
- var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
+ var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);
cachedMsg?.AddReaction(reaction);
@@ -1217,9 +1217,9 @@ namespace Discord.WebSocket
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
- var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
+ var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
- var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
+ var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);
cachedMsg?.RemoveReaction(reaction);
@@ -1241,7 +1241,7 @@ namespace Discord.WebSocket
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
- var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
+ var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => (await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false)) as IUserMessage);
cachedMsg?.ClearReactions();
@@ -1272,7 +1272,7 @@ namespace Discord.WebSocket
{
var msg = SocketChannelHelper.RemoveMessage(channel, this, id);
bool isCached = msg != null;
- var cacheable = new Cacheable(msg, id, isCached, async () => await channel.GetMessageAsync(id));
+ var cacheable = new Cacheable(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false));
await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
index 739ba3047..368a2a730 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
@@ -141,13 +141,13 @@ namespace Discord.WebSocket
//ITextChannel
///
async Task ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options)
- => await CreateWebhookAsync(name, avatar, options);
+ => await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false);
///
async Task ITextChannel.GetWebhookAsync(ulong id, RequestOptions options)
- => await GetWebhookAsync(id, options);
+ => await GetWebhookAsync(id, options).ConfigureAwait(false);
///
async Task> ITextChannel.GetWebhooksAsync(RequestOptions options)
- => await GetWebhooksAsync(options);
+ => await GetWebhooksAsync(options).ConfigureAwait(false);
//IGuildChannel
///
diff --git a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs
index cd35d731c..60cb89ee2 100644
--- a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs
+++ b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs
@@ -49,7 +49,7 @@ namespace Discord.Webhook
public async Task ModifyAsync(Action func, RequestOptions options = null)
{
- var model = await WebhookClientHelper.ModifyAsync(_client, func, options);
+ var model = await WebhookClientHelper.ModifyAsync(_client, func, options).ConfigureAwait(false);
Update(model);
}
diff --git a/src/Discord.Net.Webhook/WebhookClientHelper.cs b/src/Discord.Net.Webhook/WebhookClientHelper.cs
index 1116662a6..992ae03ab 100644
--- a/src/Discord.Net.Webhook/WebhookClientHelper.cs
+++ b/src/Discord.Net.Webhook/WebhookClientHelper.cs
@@ -14,7 +14,7 @@ namespace Discord.Webhook
{
public static async Task GetWebhookAsync(DiscordWebhookClient client, ulong webhookId)
{
- var model = await client.ApiClient.GetWebhookAsync(webhookId);
+ var model = await client.ApiClient.GetWebhookAsync(webhookId).ConfigureAwait(false);
if (model == null)
throw new InvalidOperationException("Could not find a webhook for the supplied credentials.");
return RestInternalWebhook.Create(client, model);