6 releases (breaking)

0.7.0 Nov 30, 2024
0.6.0 Jul 10, 2024
0.5.0 Feb 23, 2024
0.3.0 Nov 7, 2023
0.1.0 Mar 10, 2023

#797 in Game dev

Download history 3/week @ 2024-08-18 23/week @ 2024-08-25 80/week @ 2024-09-01 197/week @ 2024-09-08 75/week @ 2024-09-15 51/week @ 2024-09-22 74/week @ 2024-09-29 76/week @ 2024-10-06 61/week @ 2024-10-13 36/week @ 2024-10-20 61/week @ 2024-10-27 71/week @ 2024-11-03 55/week @ 2024-11-10 59/week @ 2024-11-17 167/week @ 2024-11-24 129/week @ 2024-12-01

413 downloads per month
Used in 5 crates

MIT/Apache

7KB

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!

Dependencies

~21–32MB
~517K SLoC