Skip to content

Specifying unhandledrejection behavior #16

Closed
@jridgewell

Description

@jridgewell

Re: nodejs/node#46262

What do we imagine is the correct context when an unhandledrejection is triggered? Given:

const ctx = new AsyncContext();

ctx.run("reg", () => {
  addEventLitener('unhandledrejection', () => {
    // ???
    console.log(ctx.getStore());
  });
})

let reject;
ctx.run("init", () => {
  new Promise((_, rej) => {
    reject = rej;
  });
});

ctx.run("call", () => reject('boom'));

Our options include:

  1. reg, which is the context at the time of the unhandledrejection's handler's registration
  2. init, which is the context at the time of the promise's creation
  3. call, which is the context at the time of the promise's rejection
  4. undefined, which is the context at the time unhandledrejection handler is called

Also relevant, the call-time choice allows does not prevent you from using init-time behavior, you just need to wrap your reject:

let reject;
ctx.run(123, () => {
  new Promise((_, rej) => {
    reject = AsyncContext.wrap(rej);
  });
});
ctx.run(321, () => reject('boom'));

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