Skip to content

Impossible to catch interruptions when returning promises #42

Open
@damianofalcioni

Description

@damianofalcioni

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions