Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ namespace {{packageName}}.{{clientPackage}}
/// <typeparam name="TTokenBase"></typeparam>
{{>visibility}} class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand Down Expand Up @@ -85,7 +89,7 @@ namespace {{packageName}}.{{clientPackage}}
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>{{nrt?}} tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ namespace {{packageName}}.{{clientPackage}}
internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler{{nrt?}} TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace {{packageName}}
/// </summary>
{{>visibility}} abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
/// <typeparam name="TTokenBase"></typeparam>
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand All @@ -47,7 +51,7 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public abstract class TokenBase


internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace Org.OpenAPITools
/// </summary>
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
/// <typeparam name="TTokenBase"></typeparam>
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand All @@ -47,7 +51,7 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public abstract class TokenBase


internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace Org.OpenAPITools
/// </summary>
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
/// <typeparam name="TTokenBase"></typeparam>
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand All @@ -47,7 +51,7 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public abstract class TokenBase


internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace Org.OpenAPITools
/// </summary>
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
/// <typeparam name="TTokenBase"></typeparam>
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand All @@ -47,7 +51,7 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public abstract class TokenBase


internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace Org.OpenAPITools
/// </summary>
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ namespace Org.OpenAPITools.Client
/// <typeparam name="TTokenBase"></typeparam>
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
/// <summary>
/// Dictionary mapping header names to channels of available tokens for rate limiting.
/// Each channel buffers tokens that have become available and are ready for use.
/// </summary>
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();

/// <summary>
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
Expand Down Expand Up @@ -74,7 +78,7 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
}

/// <inheritdoc/>
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
{
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public abstract class TokenBase


internal TimeSpan? Timeout { get; set; }

/// <summary>
/// Delegate for token availability notification events.
/// </summary>
/// <param name="sender">The token that became available.</param>
public delegate void TokenBecameAvailableEventHandler(object sender);

/// <summary>
/// Event raised when a rate-limited token becomes available for use.
/// </summary>
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace Org.OpenAPITools
/// </summary>
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
{
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
/// <summary>
/// Gets a token asynchronously for the specified header.
/// </summary>
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
/// <returns>A task that returns the requested token.</returns>
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
}
}
Loading
Loading