DiscordRateLimiter
public final class DiscordRateLimiter : DiscordRateLimiterSpec
The DiscordRateLimiter is in charge of making sure we don’t flood Discord with requests. It keeps a dictionary of DiscordRateLimitKeys and DiscordRateLimits. All requests to the REST api should be routed through the DiscordRateLimiter. If a DiscordRateLimit determines we have hit a limit, we add the request and its callback to the limit’s queue. After that it is up to the DiscordRateLimit to decide when to make the request. TODO handle the global rate limit
-
The queue that request responses are called on.
Declaration
Swift
public let callbackQueue: DispatchQueue -
Whether or not this rate limiter should immediately callback on rate limits.
Declaration
Swift
public let failFast: Bool
-
Creates a new DiscordRateLimiter with the specified callback queue.
Declaration
Swift
public init(callbackQueue: DispatchQueue, failFast: Bool)
-
Executes a request through the rate limiter. If the rate limit is hit, the request is put in a queue and executed later.
Declaration
Swift
public func executeRequest(_ request: URLRequest, for endpointKey: DiscordRateLimitKey, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ())Parameters
requestThe request to execute.
forThe endpoint key.
callbackThe callback for this request.
-
Executes a request through the rate limiter. If the rate limit is hit, the request is put in a queue and executed later.
Declaration
Swift
public func executeRequest(endpoint: DiscordEndpoint, token: DiscordToken, requestInfo: DiscordEndpoint.EndpointRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> ())Parameters
endpointThe endpoint for this request.
tokenThe token to use in this request.
requestInfoA
DiscordEndpoint.EndpointRequestspecifying the request info.callbackThe callback for this request.
DiscordRateLimiter Class Reference