pub struct Cluster { /* private fields */ }Expand description
A Cluster manages multiple Gateway Shards.
The Cluster handles:
- Spawning and managing shard tasks
- Coordinating identify rate limiting across shards
- Aggregating events from all shards
§Example
ⓘ
use titanium_gateway::{Cluster, ClusterConfig, ShardRange};
use titanium_model::Intents;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClusterConfig::new(
"your-token",
Intents::GUILDS | Intents::GUILD_MESSAGES,
ShardRange::All { total: 1 },
);
let (cluster, mut events) = Cluster::new(config);
cluster.start().await?;
while let Ok((shard_id, event)) = events.recv_async().await {
println!("Shard {}: {:?}", shard_id, event);
}
Ok(())
}Implementations§
Source§impl Cluster
impl Cluster
Sourcepub fn new(config: ClusterConfig) -> (Self, Receiver<(u16, Event<'static>)>)
pub fn new(config: ClusterConfig) -> (Self, Receiver<(u16, Event<'static>)>)
Create a new Cluster.
Returns the Cluster and a receiver for events from all shards. Events are tagged with the shard ID they came from.
Sourcepub async fn start(&self) -> Result<(), GatewayError>
pub async fn start(&self) -> Result<(), GatewayError>
Start all shards.
This spawns a task for each shard and begins connecting to Discord.
Shards will connect with proper rate limiting based on max_concurrency.
Sourcepub fn shard_state(&self, shard_id: u16) -> Option<ShardState>
pub fn shard_state(&self, shard_id: u16) -> Option<ShardState>
Get the state of a specific shard.
Sourcepub fn shard_latency(&self, shard_id: u16) -> Option<Duration>
pub fn shard_latency(&self, shard_id: u16) -> Option<Duration>
Get the last measured latency for a specific shard.
Auto Trait Implementations§
impl Freeze for Cluster
impl !RefUnwindSafe for Cluster
impl Send for Cluster
impl Sync for Cluster
impl Unpin for Cluster
impl !UnwindSafe for Cluster
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more