Skip to content

Commit

Permalink
documentation!
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Sep 28, 2024
1 parent cfe43da commit c6f98b9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/gateway/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,30 @@ impl ConnectedUsers {
}

/// Deregister a [GatewayUser] from the [ConnectedUsers] instance.
///
/// ## Locking
///
/// This method acquires a write lock on `store` for the duration of its runtime.
pub fn deregister(&self, user: &GatewayUser) {
self.store.write().inboxes.remove(&user.id);
self.store.write().users.remove(&user.id);
}

/// Get the "inbox" of a [GatewayUser] by its Snowflake ID.
///
/// ## Locking
///
/// This method acquires a read lock on `store` for the duration of its runtime.
pub async fn inbox(&self, id: Snowflake) -> Option<tokio::sync::broadcast::Sender<Event>> {
self.store.read().inboxes.get(&id).cloned()
}

/// Create a new [GatewayUser] with the given Snowflake ID, [GatewayClient]s, and subscriptions.
/// Registers the new [GatewayUser] with the [ConnectedUsers] instance.
///
/// ## Locking
///
/// This method calls [Self::register]. Refer to that method for information on locking behavior.
pub fn new_user(
&self,
clients: HashMap<String, Arc<Mutex<GatewayClient>>>,
Expand All @@ -371,6 +383,10 @@ impl ConnectedUsers {

/// Create a new [GatewayClient] with the given [GatewayUser], [Connection], and other data.
/// Also handles appending the new [GatewayClient] to the [GatewayUser]'s list of clients.
///
/// ## Locking
///
/// This method acquires a lock on the [Arc<Mutex<GatewayUser>>] that is passed as `user`.
#[allow(clippy::too_many_arguments)]
pub async fn new_client(
&self,
Expand Down Expand Up @@ -418,6 +434,8 @@ impl PartialEq for GatewayUser {
impl Eq for GatewayUser {}

impl GatewayClient {
/// Disconnects a [GatewayClient] properly, including un-registering it from the memory store
/// and creating a resumeable session.
pub async fn die(mut self, connected_users: ConnectedUsers) {
self.kill_send.send(()).unwrap();
let disconnect_info = DisconnectInfo {
Expand All @@ -442,6 +460,9 @@ impl GatewayClient {
}

#[derive(Default, Clone)]
/// `BulkMessageBuilder` can be used to build and send GatewayMessages to the inboxes of all
/// currently connected [GatewayClients](GatewayClient). Recipients can be added either via
/// User or Role snowflake IDs.
pub struct BulkMessageBuilder {
users: Vec<Snowflake>,
roles: Vec<Snowflake>,
Expand Down

0 comments on commit c6f98b9

Please sign in to comment.