Skip to content

Commit

Permalink
Dispose cancellationtokens when not needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Sep 25, 2018
1 parent d674cec commit 0bb2c24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
29 changes: 20 additions & 9 deletions DSharpPlus.Interactivity/InteractivityExtension.cs
Expand Up @@ -118,6 +118,7 @@ public async Task<MessageContext> WaitForMessageAsync(Func<DiscordMessage, bool>
finally
{
this.Client.MessageCreated -= Handler;
ct.Dispose();
}

#region Handler
Expand Down Expand Up @@ -173,7 +174,8 @@ public async Task<ReactionContext> WaitForReactionAsync(Func<DiscordEmoji, bool>
finally
{
this.Client.MessageReactionAdded -= Handler;
}
ct.Dispose();
}

#region Handler
async Task Handler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -233,7 +235,8 @@ public async Task<ReactionContext> WaitForReactionAsync(Func<DiscordEmoji, bool>
finally
{
this.Client.MessageReactionAdded -= Handler;
}
ct.Dispose();
}

#region Handler
async Task Handler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -297,7 +300,8 @@ public async Task<ReactionContext> WaitForMessageReactionAsync(Func<DiscordEmoji
finally
{
this.Client.MessageReactionAdded -= Handler;
}
ct.Dispose();
}

#region Handler
async Task Handler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -361,7 +365,8 @@ public async Task<ReactionContext> WaitForMessageReactionAsync(DiscordMessage me
finally
{
this.Client.MessageReactionAdded -= Handler;
}
ct.Dispose();
}

#region Handler
async Task Handler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -435,7 +440,8 @@ public async Task<ReactionCollectionContext> CreatePollAsync(DiscordMessage mess
this.Client.MessageReactionAdded -= ReactionAddHandler;
this.Client.MessageReactionRemoved -= ReactionRemoveHandler;
this.Client.MessageReactionsCleared -= ReactionClearHandler;
}
ct.Dispose();
}

#region Handlers
async Task ReactionAddHandler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -523,7 +529,8 @@ public async Task<ReactionCollectionContext> CollectReactionsAsync(DiscordMessag
this.Client.MessageReactionAdded -= ReactionAddHandler;
this.Client.MessageReactionRemoved -= ReactionRemoveHandler;
this.Client.MessageReactionsCleared -= ReactionClearHandler;
}
ct.Dispose();
}

#region Handlers
async Task ReactionAddHandler(MessageReactionAddEventArgs e)
Expand Down Expand Up @@ -594,7 +601,8 @@ public async Task<TypingContext> WaitForTypingUserAsync(DiscordChannel channel,
finally
{
this.Client.TypingStarted -= Handler;
}
ct.Dispose();
}

#region Handler
async Task Handler(TypingStartEventArgs e)
Expand Down Expand Up @@ -667,7 +675,8 @@ public async Task<TypingContext> WaitForTypingChannelAsync(DiscordUser user, Tim
finally
{
this.Client.TypingStarted -= handler;
}
ct.Dispose();
}
}
#endregion

Expand Down Expand Up @@ -748,7 +757,9 @@ public async Task<TypingContext> WaitForTypingChannelAsync(DiscordUser user, Tim
this.Client.MessageReactionAdded -= ReactionAddHandler;
this.Client.MessageReactionRemoved -= ReactionRemoveHandler;

switch (timeout_behaviour)
ct.Dispose();

switch (timeout_behaviour)
{
case TimeoutBehaviour.Ignore:
break;
Expand Down
1 change: 1 addition & 0 deletions DSharpPlus/DiscordShardedClient.cs
Expand Up @@ -724,6 +724,7 @@ private async Task<int> GetShardCountAsync()
http.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", Utilities.GetUserAgent());
http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", Utilities.GetFormattedToken(this.Config));
var resp = await http.GetAsync(url).ConfigureAwait(false);
http.Dispose();

var jo = JObject.Parse(await resp.Content.ReadAsStringAsync().ConfigureAwait(false));
if (jo["shards"] != null)
Expand Down

0 comments on commit 0bb2c24

Please sign in to comment.