Skip to content

Commit

Permalink
Introduce cancellation token
Browse files Browse the repository at this point in the history
  • Loading branch information
Itamaram committed Aug 18, 2023
1 parent bb09117 commit d138cb9
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 131 deletions.
4 changes: 2 additions & 2 deletions Backend/Remora.Discord.Gateway/DiscordGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ private async Task<Result> CreateNewSessionAsync(CancellationToken ct = default)
(
new Identify
(
await _tokenStore.GetTokenAsync(),
await _tokenStore.GetTokenAsync(ct),
_gatewayOptions.ConnectionProperties,
false,
_gatewayOptions.LargeThreshold,
Expand Down Expand Up @@ -811,7 +811,7 @@ private async Task<Result> ResumeExistingSessionAsync(CancellationToken ct = def
(
new Resume
(
await _tokenStore.GetTokenAsync(),
await _tokenStore.GetTokenAsync(ct),
_sessionInformation.SessionID,
_sessionInformation.SequenceNumber
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override async Task<HttpResponseMessage> SendAsync
CancellationToken cancellationToken
)
{
var token = await _tokenStore.GetTokenAsync();
var token = await _tokenStore.GetTokenAsync(cancellationToken);
var tokenType = _tokenStore.TokenType;

if (string.IsNullOrWhiteSpace(token))
Expand Down
4 changes: 3 additions & 1 deletion Backend/Remora.Discord.Rest/IAsyncTokenStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;

Expand All @@ -34,8 +35,9 @@ public interface IAsyncTokenStore
/// <summary>
/// Gets the token.
/// </summary>
/// <param name="cancellationToken">A cancellation token to cancel operation.</param>
/// <returns>The token's value.</returns>
ValueTask<string> GetTokenAsync();
ValueTask<string> GetTokenAsync(CancellationToken cancellationToken);

/// <summary>
/// Gets the type of the token.
Expand Down
53 changes: 0 additions & 53 deletions Backend/Remora.Discord.Rest/LazyTokenStore.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Backend/Remora.Discord.Rest/StaticTokenStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;

Expand All @@ -34,7 +35,7 @@ public class StaticTokenStore : IAsyncTokenStore
private readonly ValueTask<string> _token;

/// <inheritdoc />
public ValueTask<string> GetTokenAsync() => _token;
public ValueTask<string> GetTokenAsync(CancellationToken cancellationToken) => _token;

/// <inheritdoc />
public DiscordTokenType TokenType { get; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task ReturnsCorrectValue()
{
var tokenStore = new StaticTokenStore("Hello world!", DiscordTokenType.Bearer);

Assert.Equal("Hello world!", await tokenStore.GetTokenAsync());
Assert.Equal("Hello world!", await tokenStore.GetTokenAsync(default));
}
}

Expand Down

0 comments on commit d138cb9

Please sign in to comment.