Crate lighty_event

Crate lighty_event 

Source
Expand description

Event system for LightyLauncher

Simple broadcast-based event system that allows emitting events from the library and subscribing to them from user code.

§Example

use lighty_event::{EventBus, Event, LaunchEvent, EventReceiveError};

#[tokio::main]
async fn main() {
    let event_bus = EventBus::new(100);
    let mut receiver = event_bus.subscribe();

    // Spawn a listener with error handling
    tokio::spawn(async move {
        loop {
            match receiver.next().await {
                Ok(event) => {
                    match event {
                        Event::Launch(LaunchEvent::InstallProgress { bytes }) => {
                            println!("Downloaded {} bytes", bytes);
                        }
                        _ => {}
                    }
                }
                Err(EventReceiveError::BusDropped) => {
                    println!("Event bus closed");
                    break;
                }
                Err(EventReceiveError::Lagged { skipped }) => {
                    eprintln!("Receiver lagged, missed {} events", skipped);
                }
            }
        }
    });

    // Use the launcher with event_bus...
}

Re-exports§

pub use module::AuthEvent;
pub use module::CoreEvent;
pub use module::JavaEvent;
pub use module::LaunchEvent;
pub use module::LoaderEvent;

Modules§

module
Event modules for different components

Structs§

EventBus
Event bus for broadcasting events to multiple listeners
EventReceiver
Receiver for events from an EventBus

Enums§

Event
Root event enum containing all event types
EventReceiveError
Errors that can occur when receiving events
EventSendError
Errors that can occur when sending events
EventTryReceiveError
Errors that can occur when trying to receive events (non-blocking)

Type Aliases§

EventReceiveResult
Type alias for event receive operations
EventSendResult
Type alias for event send operations
EventTryReceiveResult
Type alias for event try receive operations