Skip to content

async-hooks: Is that possible to expose PromiseHooks resolve callback? #14038

Description

@JiaLiPassion

I am still working on porting zone.js with async_hooks. currently when I porting Promise, I met a problem and I think I need the resolve hook to be exposed.

case1: promise's parent is an resolved promise.

const p1 = Promise.resolve();

const p2 = p1.then(r => r);

In this case, current async_hooks API is ok, I can just schedule a microTask in zone.js in the init callback.

function init(id: number, provider: string, triggerId: number, parentHandle: any) {
    if (provider === PROMISE_PROVIDER) {
      if (!parentHandle) {
        return;
      }
      const parentId = parentHandle.parentId;
      if (!parentId) {
        return;
      }

      const task = Zone.current.scheduleMicroTask(PROMISE_SOURCE, noop, null, noop);
      promiseTasks[id] = task;
    }
  }

case2: the promise's parent is an unresolved promise.

const p1 = new Promise((resolve, reject) => {
    setTimeout(resolve, 3000);
});

const p2 = p1.then(r => r);

In this case, the microTask should not be scheduled in init, when the p1.then is called, because p1 is still unresolved, the microtask should be scheduled when p1.resolve is
called, so I wonder is that possible to expose the PromiseHook.resolve callback through async_hooks?

Thank you very much!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions