#coroutine #async-executor #synchronous #loops #single-threaded #blazingly #unity

koryto

🎮 game loop + 🐷 coroutine + 🌯 burrito = 🚀🔥 blazingly synchronous async executor for games 🔥🚀

4 releases

0.1.1 Jul 5, 2023
0.1.0 Jul 5, 2023
0.0.2 Jul 4, 2023
0.0.1 Jul 4, 2023

#8 in #blazingly

23 downloads per month

MIT license

450KB
121 lines

🐷 Koryto 🐷

Crates.io Documentation Build Status License

Pronounced like corrito, which is pronounced as if you combined coroutine and burrito, because everyone knows coroutines are burritos in the category of endofunctors.

Game loop focused async executor for all your coroutine needs. Inspired by macroquad's experimental coroutines, the cosync crate, Unity's amazing coroutines, and lastly Godot's coroutines which for a while weren't true burritos.

Koryto in Czech means trough, which is the thingy pigs eat from.

Koryto is single threaded and simple. The executor context Koryto expects to be polled every frame with the game's delta time.

Example

// Create a new instance of the executor
let mut ko = Koryto::new();

// Shared state the coroutine sets
let val = Rc::new(RefCell::new(3));
let val_inner = val.clone();

// Start a new coroutine
ko.start(async move {
    wait_seconds(0.5).await;

    *val_inner.borrow_mut() = 9
});

// Delta time obtained from the game loop
let dt = 0.2;

// Poll coroutines as part of the game loop
ko.poll_coroutines(dt);
assert_eq!(*val.borrow(), 3);

ko.poll_coroutines(dt);
assert_eq!(*val.borrow(), 3);

// At this point 0.5 seconds have passed and we observe the coroutine be
// resumed and set the value.
ko.poll_coroutines(dt);
assert_eq!(*val.borrow(), 9);

ko.poll_coroutines(dt);
assert_eq!(*val.borrow(), 9);

FAQ

Is this stable?

No.

Why not just use cosync when this does exactly the same thing?

While cosync does work its API is a little more flexible than feels convenient for games. Macroquad's coroutines are more closely aligned with the philosophy of this crate. If you like cosync, keep using it!

One benefit of koryto over cosync is that it does not assume coroutines are Sync.

License

koryto is dual licensed:

Dependencies