#event-system #executor #events #future #geese #async #run-time

geese_executor

Asynchronous executor with Geese event system integration

4 releases

0.1.3 Jul 22, 2023
0.1.2 Apr 30, 2023
0.1.1 Feb 20, 2023
0.1.0 Feb 7, 2023

#2013 in Asynchronous

22 downloads per month

MIT/Apache and GPL-3.0-or-later

12KB
147 lines

geese_executor

Crates.io Docs.rs

Geese executor is a runtime for futures, integrated into the Geese event system. It provides the ability to perform asynchronous work and then send the results back via events. Each time the geese_executor::notify::Poll event is raised, each future will be polled a single time, and any events raised by futures will be broadcast to all other systems.

A simple example of executor usage is provided below.

use geese::*;
use geese_executor::*;

struct A {
    cancellation: CancellationToken,
    result: Option<i32>
}

impl A {
    async fn do_background_work() -> i32 {
        // Do some awaiting
        42
    }

    fn handle_result(&mut self, future_result: &i32) {
        self.result = Some(*future_result);
    }
}

impl GeeseSystem for A {
    const DEPENDENCIES: Dependencies = dependencies()
        .with::<GeeseExecutor>();

    const EVENT_HANDLERS: EventHandlers<Self> = event_handlers()
        .with(Self::handle_result);

    fn new(ctx: GeeseContextHandle<Self>) -> Self {
        let cancellation = CancellationToken::default();
        let result = None;

        ctx.get::<GeeseExecutor>().spawn_event(Self::do_background_work())
            .with_cancellation(&cancellation);

        Self { cancellation, result }
    }
}

let mut ctx = GeeseContext::default();
ctx.flush(EventQueue::default()
    .with(geese::notify::add_system::<A>())
    .with(geese_executor::notify::Poll)
);
assert_eq!(Some(42), ctx.get::<A>().result);

Dependencies

~1.3–3MB
~61K SLoC