bevy_crossbeam_event

Crates.iobevy_crossbeam_event
lib.rsbevy_crossbeam_event
version
sourcesrc
created_at2023-03-10 09:51:48.724736
updated_at2024-11-30 11:12:28.258037
descriptionFire Bevy events from crossbeam channels
homepage
repositoryhttps://github.com/johanhelsing/bevy_crossbeam_event
max_upload_size
id806318
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Johan Klokkhammer Helsing (johanhelsing)

documentation

README

bevy_crossbeam_event

crates.io MIT/Apache 2.0 crates.io docs.rs

Fire Bevy events from crossbeam channels.

Useful if you need to handle callbacks in 3rd party libraries etc. like steamworks-rs, or getting events out of tracing layers.

Usage

Add add events to your app using .add_crossbeam_event::<EventType>:

#[derive(Event, Clone, Debug)]
struct LobbyJoined(Lobby);

impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.add_crossbeam_event::<LobbyJoined>();
        app.add_startup_system(setup);
        app.add_system(handle_lobby_joined);
    }
}

Fire events by using Res<CrossbeamEventSender<EventType>> (which can be cloned and sent into callbacks):

fn setup(service: Res<ThirdPartyCode>, sender: Res<CrossbeamEventSender<LobbyJoined>>) {
    let sender = sender.clone();
    service.join_lobby(id, move |lobby| {
        sender.send(LobbyJoined(lobby));
    });
}

Handle the events just like normal Bevy events (which they are):

fn handle_lobby_joined(mut lobby_joined_events: EventReader<LobbyJoined>) {
    for lobby in lobby_joined_events.read() {
        info!("lobby joined: {lobby:?}");
    }
}

Bevy Version Support

The main branch targets the latest bevy release.

bevy bevy_crossbeam_event
0.15 0.7, main
0.14 0.6
0.13 0.5
0.12 0.3
0.11 0.2
0.10 0.1

License

bevy_crossbeam_event is dual-licensed under either

at your option.

Contributions

PRs welcome!

Commit count: 26

cargo fmt