#discord #discord-api #twilight


Discord Gateway connection queue implementation for the Twilight ecosystem

8 releases (4 breaking)

new 0.5.1 Jul 24, 2021
0.5.0 Jun 13, 2021
0.4.0 May 12, 2021
0.3.0 Jan 8, 2021
0.1.0 Oct 7, 2020

#375 in Data structures

Download history 311/week @ 2021-04-04 214/week @ 2021-04-11 129/week @ 2021-04-18 108/week @ 2021-04-25 146/week @ 2021-05-02 353/week @ 2021-05-09 308/week @ 2021-05-16 162/week @ 2021-05-23 117/week @ 2021-05-30 183/week @ 2021-06-06 315/week @ 2021-06-13 191/week @ 2021-06-20 210/week @ 2021-06-27 163/week @ 2021-07-04 214/week @ 2021-07-11 235/week @ 2021-07-18

891 downloads per month
Used in 6 crates (via twilight-gateway)

ISC license

16K SLoC

Ratelimiting functionality for queueing new gateway sessions.

The gateway ratelimits how often clients can initialize new sessions. Instances of a queue are given to shards so that they can request to initialize a session.

Queue implementations must point to the same broker so that all shards across all clusters, processes, and other forms of multi-serviced applications, can work together and use the same ratelimiting source. That is, if you for example have two clusters in two different processes, then the two processes must use some unified form of ratelimiting: this can either mean using IPC to communicate ratelimiting or a broker.

Provided queues

Most users only need the LocalQueue: it's a single-process queue for smaller bots. Larger bots need the LargeBotQueue, which supports single-process Sharding for Very Large Bots through the use of bucket releasing.

By default, the Cluster and Shards use the LocalQueue. You can override this in the ClusterBuilder::queue and ShardBuilder::queue configuration methods.

Advanced use cases

Large bots, and smaller bots out of design, may need to implement their own queue. The most common reason to need this is if you have clusters in multiple processes. You'll need a broker to manage ratelimiting across them all so a [Queue] trait is provided that shards can use to make requests to create sessions.


~245K SLoC