Re: [streams] Why is the reference implementation calling promise callbacks synchronously? (#293)

The reference implementation isn't calling promise callbacks synchronously. Instead, it is resolving/rejecting the promise, which itself will schedule the callbacks asynchronously. Here is an example with just promises that may be helpful to understand:

```js
let resolve;
const promise = new Promise(r => { resolve = r; });

promise.then(v => console.log("fulfilled", v));

resolve(5);
console.log("after resolve call");
```

This will print `"after resolve call"\n"fulfilled 5"`. Even though `resolve(5)` is called "synchronously", the way promises are specified ensures that any callbacks are scheduled to run asynchronously.

Make sense?

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/293#issuecomment-78285808

Received on Wednesday, 11 March 2015 15:27:56 UTC