This code:
var { Arena } = require("quickjs-emscripten-sync");
var ctx = (await QJS.getQuickJS()).newContext();
var arena = new Arena(ctx, {
"isMarshalable": true
});
arena.expose({
console
});
arena.evalCode(`
(async () => {
console.log(1);
await new Promise(res => res("cat"));
console.log(2);
})();
`);
It prints 1 and after I do arena.executePendingJobs();, it works printing 2.
However, I can't get an external Promise to work.
var { Arena } = require("quickjs-emscripten-sync");
var ctx = (await QJS.getQuickJS()).newContext();
var arena = new Arena(ctx, {
"isMarshalable": true
});
function someAsyncOperation() {
return new Promise(resolve => {
setTimeout(() => {
resolve("cat");
}, 1000);
});
}
arena.expose({
console, someAsyncOperation
});
arena.evalCode(`
(async () => {
console.log(1);
await someAsyncOperation();
console.log(2);
})();
`);
It prints 1 and fails with Method Promise.prototype.then called on incompatible receiver #<Promise>
Am I'm doing something wrong?
This code:
It prints 1 and after I do
arena.executePendingJobs();, it works printing 2.However, I can't get an external Promise to work.
It prints 1 and fails with
Method Promise.prototype.then called on incompatible receiver #<Promise>Am I'm doing something wrong?