GithubHelp home page GithubHelp logo

Async callbacks about piccolo HOT 3 CLOSED

kyren avatar kyren commented on August 22, 2024
Async callbacks

from piccolo.

Comments (3)

kyren avatar kyren commented on August 22, 2024

Hm, maaaaybe, but using luster for anything serious is probably a ways off. I dunno, I'd have to think about exactly how to do it.

I think after luster is more usable and has a working userdata story, you could kind of do this without specific support in luster by taking advantage of the stackless nature. You'd need to have callbacks call something that sets up some state in a userdata, then the Sequence would pause, and on every sequence step you'd have to check for that waiting state to be set. Once it is set, you could wait on the condition to be fulfilled before resuming stepping the sequence?

This works because there's a whole lot of overlap between Sequences and Futures, so they give you some of the same abilities, they just have to be different due to lifetimes and threading the garbage collector context.

Is that the sort of thing you were thinking? I know that definitely isn't automatic, but you could maybe build something automatic off of that.

from piccolo.

Ekleog avatar Ekleog commented on August 22, 2024

Hmm so I'm not sure what Sequences exactly describe in luster (I haven't actually tried to read the implementation yet, still being in the exploratory phase). If I understand correctly, the process would be similar to:

  • Compile the Lua code
  • Start a Lua VM with the compiled Lua code
  • When wanting to call a Lua function asynchronously:
    • β€œCall” the function on the Lua VM, this gives back a Sequence to be executed
    • Step-forward the Sequence, this processes the Lua code until the first builtin call
    • Try to asynchronously perform the builtin call, if it isn't ready, keep the paused Sequence and propagate not-readiness upwards to the (rust) caller
    • When it is ready, step-forward the Sequence again with the result of the builtin call, and go back to above point

If that is indeed approximately what you mean, then I think it'd be possible to wrap a library over this model so that it could be transparently be used as async, and thus that this issue will solve itself then!

Thank you for your answer, and sorry if I'm misunderstanding something for lack of knowledge of luster's internals. As for luster not being ready, don't worry, my project is very far from being ready too! hopefully we'll manage to get to something usable approximately simultaneously :)

from piccolo.

kyren avatar kyren commented on August 22, 2024

This is an extremely old issue, but I never responded to the question because this was about when I stopped working on the project for four years. I'm going through old PRs / issues right now.

When wanting to call a Lua function asynchronously:

  • β€œCall” the function on the Lua VM, this gives back a Sequence to be executed
  • Step-forward the Sequence, this processes the Lua code until the first builtin call
  • Try to asynchronously perform the builtin call, if it isn't ready, keep the paused Sequence and propagate not-readiness upwards to the (rust) caller
  • When it is ready, step-forward the Sequence again with the result of the builtin call, and go back to above point

This is actually exactly how you would do it. Nowadays, you would specifically use Fuel::interrupt to cause the Executor::step driving Lua code to immediately return to Rust, (after registering some waker somewhere, or in some other way propagating unreadiness). I should make an example of this and put it somewhere...

from piccolo.

Related Issues (20)

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.