GithubHelp home page GithubHelp logo

cosync's People

Contributors

sanbox-irl avatar sapir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cosync's Issues

Borrowed inputs to tasks

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.

Multiple tasks within a single `Cosync`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.