bevy_flurx_ipc

Crates.iobevy_flurx_ipc
lib.rsbevy_flurx_ipc
version
sourcesrc
created_at2024-06-02 14:25:17.909142+00
updated_at2025-02-24 18:23:57.678316+00
descriptionprovides a way for ipc communication using bevy_flurx
homepage
repositoryhttps://github.com/not-elm/bevy_webview_projects
max_upload_size
id1259235
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
elm (not-elm)

documentation

README

bevy_flurx_ipc

This library assists in implementing inter-process communication and is also part of bevy_webview_wry.

Use bevy_flurx for interprocess communication. Its provides a mechanism similar to coroutines, making it easy to implement asynchronous communication.

Usage

use bevy::prelude::*;
use bevy_flurx::prelude::*;
use bevy_flurx_ipc::prelude::*;

#[derive(Resource)]
struct Count(usize);

fn main() {
    App::new()
        .add_plugins((
            MinimalPlugins,
            FlurxPlugin,
            FlurxIpcPlugin,
        ))
        .insert_resource(Count(0))
        .add_systems(Startup, setup)
        .add_systems(Update, resolve_event)
        .run();
}

fn increment() -> ActionSeed<usize, usize> {
    once::run(|In(n): In<usize>, mut count: ResMut<Count>| {
        count.0 += n;
        count.0
    })
}

#[command]
async fn increment_command(
    In(n): In<usize>,
    task: ReactorTask,
) -> usize {
    task.will(Update, increment().with(n)).await
}

fn setup(
    mut commands: Commands,
    ipc_commands: Res<IpcCommands>,
) {
    let entity = commands.spawn(IpcHandlers::new([
        increment_command,
    ])).id();

    // This time, threads are treated as other processes.
    let ipc_commands = ipc_commands.clone();
    std::thread::spawn(move || {
        let mut count = 0;
        loop {
            std::thread::sleep(std::time::Duration::from_secs(1));
            count += 1;
            ipc_commands.push(IpcCommand {
                entity,
                payload: Payload {
                    // Call `increment_command` command.
                    id: "increment_command".to_string(),
                    args: Some(format!("{count}")),
                    // ID to identify the caller
                    resolve_id: 0,
                },
            });
        }
    });
}

fn resolve_event(
    mut er: EventReader<IpcResolveEvent>
) {
    for e in er.read() {
        info!("Resolved: {:?}", e);
    }
}
Commit count: 159

cargo fmt