pub struct ShardQueuer {Show 14 fields
pub data: Arc<RwLock<TypeMap>>,
pub event_handlers: Vec<Arc<dyn EventHandler>>,
pub raw_event_handlers: Vec<Arc<dyn RawEventHandler>>,
pub framework: Arc<OnceLock<Arc<dyn Framework>>>,
pub last_start: Option<Instant>,
pub manager: Arc<ShardManager>,
pub queue: VecDeque<ShardInfo>,
pub runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>,
pub rx: UnboundedReceiver<ShardQueuerMessage>,
pub ws_url: Arc<Mutex<String>>,
pub cache: Arc<Cache>,
pub http: Arc<Http>,
pub intents: GatewayIntents,
pub presence: Option<PresenceData>,
}
Expand description
The shard queuer is a simple loop that runs indefinitely to manage the startup of shards.
A shard queuer instance should be run in its own thread, due to the blocking nature of the loop itself as well as a 5 second thread sleep between shard starts.
Fields§
§data: Arc<RwLock<TypeMap>>
A copy of Client::data
to be given to runners for contextual dispatching.
event_handlers: Vec<Arc<dyn EventHandler>>
A reference to an EventHandler
, such as the one given to the Client
.
raw_event_handlers: Vec<Arc<dyn RawEventHandler>>
A reference to an RawEventHandler
, such as the one given to the Client
.
framework: Arc<OnceLock<Arc<dyn Framework>>>
A copy of the framework
last_start: Option<Instant>
The instant that a shard was last started.
This is used to determine how long to wait between shard IDENTIFYs.
manager: Arc<ShardManager>
A copy of the ShardManager
to communicate with it.
queue: VecDeque<ShardInfo>
The shards that are queued for booting.
This will typically be filled with previously failed boots.
runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>
A copy of the map of shard runners.
rx: UnboundedReceiver<ShardQueuerMessage>
A receiver channel for the shard queuer to be told to start shards.
ws_url: Arc<Mutex<String>>
A copy of the URL to use to connect to the gateway.
cache: Arc<Cache>
§http: Arc<Http>
§intents: GatewayIntents
§presence: Option<PresenceData>
Implementations§
Source§impl ShardQueuer
impl ShardQueuer
Sourcepub async fn run(&mut self)
pub async fn run(&mut self)
Begins the shard queuer loop.
This will loop over the internal Self::rx
for ShardQueuerMessage
s, blocking for
messages on what to do.
If a ShardQueuerMessage::Start
is received, this will:
- Check how much time has passed since the last shard was started
- If the amount of time is less than the ratelimit, it will sleep until that time has passed
- Start the shard by ID
If a ShardQueuerMessage::Shutdown
is received, this will return and the loop will be
over.
Note: This should be run in its own thread due to the blocking nature of the loop.
Sourcepub async fn shutdown(&mut self, shard_id: ShardId, code: u16)
pub async fn shutdown(&mut self, shard_id: ShardId, code: u16)
Attempts to shut down the shard runner by Id.
Note: If the receiving end of an mpsc channel - owned by the shard runner - no longer exists, then the shard runner will not know it should shut down. This should never happen. It may already be stopped.