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

Asynchronous #14

Open
ForbesLindesay opened this issue Feb 10, 2013 · 2 comments
Open

Asynchronous #14

ForbesLindesay opened this issue Feb 10, 2013 · 2 comments

Comments

@ForbesLindesay
Copy link
Member

We've had the discussion and accepted that Promises/A+ promises are always asynchronous for then but what about for calls to resolve

let {promise, resolve} = defer();
console.log(1);
promise.then(() => console.log(4));
console.log(2);
resolve(null);
console.log(3);

If resolve is allowed to be synchronous, this could result in:

1
2
4
3

But if it must be asynchronous then it must result in

1
2
3
4

Because of the restrictions of Promises/A+ it can never result in

1
4
2
3

So what's it to be? Do we force asynchronous behavior?

@domenic
Copy link
Member

domenic commented Feb 10, 2013

Very interesting, thanks for bringing this up! My first instinct is that synchronicity would be bizarre. But, not based on anything concerete yet.

Let's try this similar scenario:

let {promise, resolve} = defer();
console.log(1);
resolve(null);
promise.then(() => console.log(4));
console.log(2);
console.log(3);

The only thing this can be, by Promises/A+, is

1
2
3
4

To me it seems weird that the output would change depending on whether you hooked up the then before or after the resolve.

@ForbesLindesay
Copy link
Member Author

Another question is how that plays with 'synchronous inspection'.

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