Domenic Denicola <mailto:[email protected]>
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!
/be
[something called a microtask][2], but it's deeply coupled with the
`MutationObserver` objects at the moment.
[1]: https://www.w3.org/Bugs/Public/show_bug.cgi?id=22296
[2]:
http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#perform-a-microtask-checkpoint
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
Tab Atkins Jr. <mailto:[email protected]>
August 31, 2013 2:13 PM
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.
~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
Nathan Wall <mailto:[email protected]>
August 31, 2013 9:03 AM
Hi, 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
http://github.com/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 http://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 around
`setTimeout(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
http://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
http://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
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss