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

Impossible to catch interruptions when returning promises #42

Open
damianofalcioni opened this issue Oct 18, 2024 · 0 comments
Open

Impossible to catch interruptions when returning promises #42

damianofalcioni opened this issue Oct 18, 2024 · 0 comments

Comments

@damianofalcioni
Copy link

Hi,
I have the following code for quickjs-emscripten that handle correctly the interruption:

const QuickJS = await getQuickJS();
const runtime = QuickJS.newRuntime();
runtime.setInterruptHandler(shouldInterruptAfterDeadline(Date.now() + 1000));
const vm = runtime.newContext();
const result = vm.unwrapResult(vm.evalCode("new Promise((out,err)=>{i = 0; while (1) { i++; } out(i);});"));
const promise = result.consume(result=>vm.resolvePromise(result));
vm.runtime.executePendingJobs();
const resolvedPromise = await promise;
if (resolvedPromise.error) {
  const errorJson = vm.dump(resolvedPromise.error);
  console.log(errorJson);
  resolvedPromise.error.dispose();
}

but when I try to recreate it with quickjs-emscripten-sync it do not catch and terminate Node:

const runtime = (await getQuickJS()).newRuntime();
runtime.setInterruptHandler(shouldInterruptAfterDeadline(Date.now() + 1000));
const vm = runtime.newContext();
const arena = new Arena(vm, { isMarshalable: true });
try{
  const result = arena.evalCode("new Promise((out,err)=>{i = 0; while (1) { i++; } out(i);});");
  arena.executePendingJobs();
  console.log(await result);
}catch(e) {
  console.error(e.message);
}

error:

> node index

npm error Lifecycle script `run` failed with error:
npm error code 13

I did something wrong?
Thanks

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

1 participant