Struct skua::gateway::ShardQueuer

source ·
pub struct ShardQueuer {
Show 15 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 voice_manager: Option<Arc<dyn VoiceGatewayManager + 'static>>, pub ws_url: Arc<Mutex<String>>, pub cache: Arc<Cache>, pub http: Arc<Http>, pub intents: GatewayIntents, pub presence: Option<PresenceData>,
}
Available on crate feature gateway only.
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>>>
Available on crate feature framework only.

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.

§voice_manager: Option<Arc<dyn VoiceGatewayManager + 'static>>
Available on crate feature voice only.

A copy of the client’s voice manager.

§ws_url: Arc<Mutex<String>>

A copy of the URL to use to connect to the gateway.

§cache: Arc<Cache>
Available on crate feature cache only.
§http: Arc<Http>§intents: GatewayIntents§presence: Option<PresenceData>

Implementations§

source§

impl ShardQueuer

source

pub async fn run(&mut self)

Begins the shard queuer loop.

This will loop over the internal Self::rx for ShardQueuerMessages, blocking for messages on what to do.

If a ShardQueuerMessage::Start is received, this will:

  1. Check how much time has passed since the last shard was started
  2. If the amount of time is less than the ratelimit, it will sleep until that time has passed
  3. 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.

source

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 - theoretically 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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more