quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Promise and await problem

Open AndyGuoPLZ opened this issue 3 years ago • 1 comments

it seems there are some issues in Promise and Await synax: eg:jsContext.executeVoidScript("console.log("Hello World");\n" + "function testAsync(params) {\n" + " console.log("test Async start");\n" + " return new Promise(function (resolve, reject) {\n" + " resolve("done");\n" + " });\n" + "}\n" + "\n" + "async function main(){\n" + " var t = await testAsync(11);\n" + " console.log("test finish"+t);\n" + "}\n" + "main();",null); The log in console only shows Hello world and test Async start And the "test finish" has been gone and it seems it has been blocked at the line " var t = await testAsync(11);\n" +"

AndyGuoPLZ avatar Sep 08 '22 07:09 AndyGuoPLZ

You need to run the tasks on the job queue. See:

JS_EnqueueJob(), JS_IsJobPending(), JS_ExecutePendingJob()

andrewrch avatar Sep 08 '22 07:09 andrewrch