pub fn create_bucket<F: Fn(ShardId, ConfigBuilder) -> Config>(
bucket_id: u64,
concurrency: u64,
total: u64,
config: Config,
per_shard_config: F
) -> impl Iterator<Item = Shard>
Expand description

Create a single bucket’s worth of shards.

Passing a primary config is required. Further customization of this config may be performed in the callback.

Examples

Start bucket 2 out of 10 with 100 shards in total and collect them into a list:

use std::env;
use twilight_gateway::{stream, Config, Intents};

let token = env::var("DISCORD_TOKEN")?;

let config = Config::new(token.clone(), Intents::GUILDS);
let shards = stream::create_bucket(2, 10, 100, config, |_, builder| builder.build())
    .map(|shard| (shard.id().number(), shard))
    .collect::<Vec<_>>();

assert_eq!(shards.len(), 10);

Panics

Panics if bucket_id >= total or if concurrency >= total.

Panics if concurrency doesn’t fit into a usize.

Panics if loading TLS certificates fails.