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

Difference with native Promise #159

Open
neewbee opened this issue Nov 16, 2019 · 2 comments
Open

Difference with native Promise #159

neewbee opened this issue Nov 16, 2019 · 2 comments

Comments

@neewbee
Copy link

neewbee commented Nov 16, 2019

new Promise((resolve, reject) => {
  resolve();
})
  .then(() => {
    console.log('outer tick0');
    new Promise((resolve, reject) => {
      resolve();
    })
      .then(() => {
        console.log('inner tick0');
        return Promise.resolve();
      })
      .then(() => {
        console.log('inner tick1');
      })
  })
  .then(() => {
    console.log('outer tick1');
  })
  .then(() => {
    console.log('outer tick2');
  })
  .then(() => {
    console.log('outer tick3');
  })
  .then(() => {
    console.log('outer tick4');
  })

// native promise output
// outer tick0
// inner tick0
// outer tick1
// outer tick2
// outer tick3
// inner tick1
// outer tick4

// then/Promise output
// outer tick0
// inner tick0
// outer tick1
// inner tick1
// outer tick2
// outer tick3
// outer tick4

What's the reason behind this?

@edef1c
Copy link
Member

edef1c commented Nov 20, 2019

I'm fairly sure the order in which the callbacks are invoked is undefined, and is thus an implementation detail you should not rely on.

@neewbee
Copy link
Author

neewbee commented Nov 21, 2019

I'm fairly sure the order in which the callbacks are invoked is undefined, and is thus an implementation detail you should not rely on.

Is the order in which the callbacks are invoked defined in the ECMAScript Specification or any other place?

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

2 participants