Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to progress promises #124

Open
lastmjs opened this issue Jan 17, 2024 · 3 comments
Open

How to progress promises #124

lastmjs opened this issue Jan 17, 2024 · 3 comments

Comments

@lastmjs
Copy link

lastmjs commented Jan 17, 2024

I see that promise_loop_poll is deprecated, though the examples show its usage. I am running into problems with promises, I don't see how to get them to progress. I have wasmedge-quickjs embedded in my own Rust program compiled to Wasm.

Any help would be appreciated, thank you! And it would be great for those examples to show the up-to-date usage.

@lastmjs
Copy link
Author

lastmjs commented Jan 17, 2024

From the discord I have learned that promise_loop_poll was removed in lieu of a Future integration. While that's nice for some use cases, this is making it difficult for my use case where I have a custom Futures implementation and use RefCell to access a global runtime. If I could just poll the promises manually I believe I would be able to proceed easily, but because I can't I have to somehow figure out how to get an async closure working, but using RefCells we generally must get everything to work in a non-async closure.

It would be wonderful to be able to poll manually again.

@lastmjs
Copy link
Author

lastmjs commented Jan 17, 2024

I went back in time to find the implementation body of promise_loop_poll and added it into my fork of wasmedge-quickjs, so far it does indeed work!

    #[deprecated]
    pub fn promise_loop_poll(&mut self) {
        unsafe {
            let rt = self.rt();
            let mut pctx: *mut JSContext = 0 as *mut JSContext;

            loop {
                let err = JS_ExecutePendingJob(rt, (&mut pctx) as *mut *mut JSContext);
                if err <= 0 {
                    if err < 0 {
                        js_std_dump_error(pctx);
                    }
                    break;
                }
            }
        }
    }

I ask for this method to be put back and not removed.

@L-jasmine
Copy link
Collaborator

Ok, I will restore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants