sanbox-irl / cosync Goto Github PK
View Code? Open in Web Editor NEWA single-threaded executor for deferred async code for games.
License: Apache License 2.0
A single-threaded executor for deferred async code for games.
License: Apache License 2.0
I'm trying to store my coroutine in a heap-allocated struct (or just heap-allocate the coroutine) and pass borrowed inputs to it in run_until_stall
.
As far as I understand, this is not possible with the current API. The problem is the type parameter of Cosync
. If my input has borrowed bits, I need a type parameter like:
struct MyInput<'a> {
borrowed_bit: &'a MyBorrowedData,
other_stuff: OtherStuff,
}
That type parameter that propogates into all the references to Cosync
:
type MyCoro<'a> = Cosync<MyInput<'a>>;
which means I can't heap-allocate MyCoro
: 'static
is the only lifetime I can pass to MyCoro
, but that's the not lifetime as I will be passing stack-allocated borrowed values to run_until_stall
.
I'm not sure how to best solve this problem in Rust. I'm wondering if you know a workaround. To solve this at the API level we would need to somehow avoid the type parameter for the coroutine input in the Cosync
type. However if we do that then I don't know how to implement the run_until_stall
method as it needs to know the coroutine input type.
Any thoughts on this?
The actual use case: In an app (not a game) I have an event source. Whenever an event arrives my callback is called with &
and &mut
, and value arguments (passed by the event loop to my callback). This callback is practically a coroutine: it takes an input (event data), it may run an action (or yield a value), or wait for more input. cosyn
makes it much simpler to implement than an hand-written coroutine as I need to implement a lot of states manually.
The problem is the callback needs to be heap allocated and passed to the event loop and I don't have control over the event loop code to change this.
I have a use case that requires the following pattern to be possible with cosync:
// Somewhere...
// Task A
cosync.queue(|| async {
do_something().await;
do_another_thing().await;
});
// Task B
cosync.queue(|| async {
do_something().await;
do_another_thing().await;
});
// Elsewhere, every tick...
cosync.run_until_stall(); // this would run both Task A and Task B until they stall
As a practical example of what I am trying to do, imagine a UI that has multiple elements within it, all of which decide they want to move across the screen, and they run that tween through Cosync. I need them all to move across the screen at the same time, but each needs to have its own task.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.