pub struct ShardRunner {
pub cache: Arc<Cache>,
pub http: Arc<Http>,
/* private fields */
}
Expand description
A runner for managing a Shard
and its respective WebSocket client.
Fields§
§cache: Arc<Cache>
§http: Arc<Http>
Implementations§
Source§impl ShardRunner
impl ShardRunner
Sourcepub fn new(opt: ShardRunnerOptions) -> Self
pub fn new(opt: ShardRunnerOptions) -> Self
Creates a new runner for a Shard.
Sourcepub async fn run(&mut self) -> Result<()>
pub async fn run(&mut self) -> Result<()>
Starts the runner’s loop to receive events.
This runs a loop that performs the following in each iteration:
-
checks the receiver for
ShardRunnerMessage
s, possibly from theShardManager
, and if there is one, acts on it. -
checks if a heartbeat should be sent to the discord Gateway, and if so, sends one.
-
attempts to retrieve a message from the WebSocket, processing it into a
GatewayEvent
. This will block for 100ms before assuming there is no message available. -
Checks with the
Shard
to determine if the gateway event is specifying an action to take (e.g. resuming, reconnecting, heartbeating) and then performs that action, if any. -
Dispatches the event via the Client.
-
Go back to 1.