[][src]Module discord_game_sdk::event

Event Types

This crate makes use of crossbeam_channel to pass events.

All event and callback handlers do a minimal amount of work possible across FFI; they send copied or cloned data. Here is why:

  • Panics in FFI must be intercepted and unwinding must be disabled
  • Passing a mutable reference to Discord would result in either mutable aliasing or deadlocks (if using Arc<Mutex<_>>)

If an event or callback handler runs into a panic across FFI, the panic will be intercepted and the process will be aborted.

IMPORTANT NOTE:

If you do not make use of all receivers, you must call Discord::empty_event_receivers or event::Receivers::empty_channels to prevent the event buffers from growing too big. A safe place to do that would be just before Discord::run_callbacks.

IMPORTANT NOTE:

Unless you plan to run Discord::run_callbacks in another thread, waiting for events will block forever. This means that try_ methods should be used and select! must contain a default clause.

IMPORTANT NOTE:

crossbeam_channel::Receivers (and event::Receivers) may be cloned but the events won't be duplicated. An event may only be received once across the whole application. Dispatching events to multiple different places is on you.

Examples


let mut discord = discord_game_sdk::Discord::new(999999999999999999)?;
let recvs = discord.event_receivers();

loop {
    discord.empty_event_receivers();
    discord.run_callbacks();

    for _ in recvs.current_user_update.try_iter() {
        println!("User updated!"),
    }
}

Modules

achievements
activities
lobbies
networking
overlay
relationships
store
users
voice

Structs

Receivers