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.
// 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);
No.
Yes, probably ... we have tests.
The source code should be simple enough for anyone to read and understand.
There's no 100 000 lines of code like in tokio. Currently koryto
does
depend on futures
in order to implement the select!/join!
combinators.
Unlike cosync
, koryto
assumes your application is single thread,
which means your futures don't need to be Send
.
This allows you to use Rc
for shared state, and also just pass around pointers
into the futures without any wrappers.
koryto
is also a bit simpler in its API and closer to Macroquad's
coroutines,
although macroquad's futures also need to be Send
.
koryto
is dual licensed:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)