koryto

Crates.iokoryto
lib.rskoryto
version0.1.1
sourcesrc
created_at2023-07-04 13:24:05.899101
updated_at2023-07-05 12:28:01.120304
description🎮 game loop + 🐷 coroutine + 🌯 burrito = 🚀🔥 blazingly synchronous async executor for games 🔥🚀
homepage
repository
max_upload_size
id907968
size456,880
Jakub Arnold (darthdeus)

documentation

README

🐷 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.

Pigs eating from a trough

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:

Commit count: 0

cargo fmt