Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Last active April 27, 2025 06:17
Show Gist options
  • Save evanrelf/e47ef926662ae2e3d413acc818688b88 to your computer and use it in GitHub Desktop.
Save evanrelf/e47ef926662ae2e3d413acc818688b88 to your computer and use it in GitHub Desktop.
// defining the plugin:
use bevy::{prelude::*, tasks::IoTaskPool};
pub struct Parker(parking::Parker);
#[derive(Resource)]
pub struct Unparker(pub parking::Unparker);
fn park_system(parker: NonSend<Parker>) {
parker.0.park();
}
pub struct ParkPlugin;
impl Plugin for ParkPlugin {
fn build(&self, app: &mut App) {
let (parker, unparker) = parking::pair();
app.insert_non_send_resource(Parker(parker))
.insert_resource(Unparker(unparker))
.add_systems(Last, park_system);
}
}
// using the plugin:
fn some_other_system(unparker: Res<Unparker>) {
let task_pool = IoTaskPool::get();
let unparker = unparker.0.clone();
let task = task_pool.spawn(async move {
// feed some input to the bevy app here
todo!();
// wake up the main thread to let bevy loose on the new inputs
unparker.unpark();
});
task.detach();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment