Skip to content

๐ŸŽฎ game loop + ๐Ÿท coroutine + ๐ŸŒฏ burrito = ๐Ÿš€๐Ÿ”ฅ blazingly synchronous async executor for games ๐Ÿ”ฅ๐Ÿš€

Notifications You must be signed in to change notification settings

darthdeus/koryto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿท 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.

Does it work?

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.

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

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.

License

koryto is dual licensed:

About

๐ŸŽฎ game loop + ๐Ÿท coroutine + ๐ŸŒฏ burrito = ๐Ÿš€๐Ÿ”ฅ blazingly synchronous async executor for games ๐Ÿ”ฅ๐Ÿš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published