AP2 bugs
The diagnosis and fix for these seem correct. Now reported at domenic/promises-unwrapping#14, domenic/promises-unwrapping#15
Thanks for reporting these!
Indeed, thanks Nathan! Feel free to file issues, or even submit pull requests, for any further bugs you encounter. That’s why we’re doing this on GitHub, after all! :)
On Sat, Aug 31, 2013 at 9:03 AM, Nathan Wall <nathan.wall at live.com> wrote:
Am I correct to understand that "queue a microtask" means that the task should be run asynchronously? For this, I am currently using a function called
defer(f)
which is just a wrapper aroundsetTimeout(f, 0)
.
Yes, but setTimeout is "more asynchronous" than a microtask. Microtasks are defined by HTML I think? Basically, a microtask is run at the end of the current script stack, just before yielding control to the browser.
Using setTimeout shouldn't be incorrect, but it will be slower than intended.
Microtasks are unfortunately not defined anywhere, but Anne has a bug open on HTML5 to do so.
Well, OK, looking at the spec, it kind of defines something called a microtask, but it's deeply coupled with the MutationObserver
objects at the moment.
Domenic Denicola <mailto:domenic at domenicdenicola.com> August 31, 2013 2:17 PM Microtasks are unfortunately not defined anywhere, but Anne has [a bug open on HTML5][1] to do so.
Right, "not defined".
Well, OK, looking at the spec, it kind of defines
"kind of defines", more precisely stated as "does not define" -- dherman and I noticed this.
I hope Anne defines it soon!
On Sat, Aug 31, 2013 at 10:56 PM, Brendan Eich <brendan at mozilla.com> wrote:
"kind of defines", more precisely stated as "does not define" -- dherman and I noticed this.
I hope Anne defines it soon!
To be clear, Ian edits HTML, not me. I just filed www.w3.org/Bugs/Public/show_bug.cgi?id=22296 and got people to put the various proposals forward. I can probably ask him to expedite it somewhat, especially once domenic/promises-unwrapping is somewhat more formally endorsed.
I do not know if this is the correct list to discuss these things. If it is not, please redirect me.
I have done some work on implementing the AP2 draft I could find here domenic/promises-unwrapping and I have a few potential bugs to report. If this is not the latest draft, please direct me to the appropriate resource to use.
My implementation is available at gist.github.com/anonymous/6399102
UpdateDerived
UpdateDerived step 2.1 says:
If IsObject(originator.[[Value]]), queue a microtask to run the following:
Am I correct to understand that "queue a microtask" means that the task should be run asynchronously? For this, I am currently using a function called
defer(f)
which is just a wrapper aroundsetTimeout(f, 0)
.Using this code as an example:
var p = new Promise(function(resolve, reject) { resolve('a'); });
p.then(function(value) { console.log(2, value); });
console.log(1);
I would expect the output to be:
1 2 a
The way the draft is currently written (as shown in this gist gist.github.com/anonymous/6399102 ), the code above will instead log:
2 a 1
However, this code:
var p = new Promise(function(resolve, reject) { resolve({ value: 'a' }); });
p.then(function(value) { console.log(2, value); });
console.log(1);
will log:
1 2 { value: 'a' }
because the "queue a microtask" only happens when the promise is resolved with an object.
I think that "queue a microtask" should be around everything after step 1 in UpdateDerived instead, as seen in this gist gist.github.com/anonymous/6399033 which will log the values in the expected order.
UpdateFromReason -> UpdateDerivedFromReason
Additionally, there's a typo where a function named UpdateFromReason is defined. I think it is intended to be called UpdateDerivedFromReason, as that's what it's called elsewhere in the document.
I welcome any comments on my implementation as well.
Nathan