Giter Club home page Giter Club logo

Comments (3)

justjake avatar justjake commented on May 30, 2024

from quickjs-emscripten.

Lyoko-Jeremie avatar Lyoko-Jeremie commented on May 30, 2024

@justjake
i think so , but the promise create in the vm , use in the vm , and resolve in the vm , where can i call the executePendingJobs ?

from quickjs-emscripten.

Lyoko-Jeremie avatar Lyoko-Jeremie commented on May 30, 2024

i find a JS_BOOL JS_IsJobPending(JSRuntime *rt); function from quickjs.h

https://github.com/bellard/quickjs/blob/2788d71e823b522b178db3b3660ce93689534e6d/quickjs.h#L874

/* JS Job support */


typedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValueConst *argv);
int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, int argc, JSValueConst *argv);


JS_BOOL JS_IsJobPending(JSRuntime *rt);
int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);

the JS_IsJobPending seems like usefull .


and after i look up the document, i find some thing :

https://github.com/justjake/quickjs-emscripten/blob/897fded554b9b1c056c830789f407690ed01a2d9/CHANGELOG.md#breaking-changes

executependingjobs()
haspendingjob()

and from the evalcode() comment :

If evaluation returned a handle containing a promise, use resolvePromise to convert it to a native promise and executePendingJobs to finish evaluating the promise.

so, i add vm.runtime.executePendingJobs() call between the vm.resolvePromise and await like follow, the above code work !

        console.log('resolvedResult');
        const resolvedResultPromise = vm.resolvePromise(promiseHandle);


        // add this
        console.log('vm.runtime.hasPendingJob()', vm.runtime.hasPendingJob());    // <============ return true
        console.log('vm.runtime.executePendingJobs()', vm.unwrapResult(vm.runtime.executePendingJobs()));
        console.log('vm.runtime.hasPendingJob()', vm.runtime.hasPendingJob());    // <============ return false


        console.log('resolvedResultPromise', resolvedResultPromise);    // <============ pending on this
        const resolvedResult = await resolvedResultPromise;

seems like the document in Readme.md need some update

from quickjs-emscripten.

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.