On 11/19/2013 10:12 AM, nsm.nik...@gmail.com wrote:
Is there are reason devtools cannot switch to DOM Promises directly rather than
go through making Promise.jsm a wrapper around DOM Promise? The current promise
implementations which allow resolving later are leading to very un-idiomatic
promise code in the tree, and the encapsulation of (resolve, reject) being
'private' to the constructor callback should force a better style and easier to
read code.
If addon-sdk allows synchronously resolving promises, I'd like to help in a
migration path that ensures these are not abused, and eventually gotten rid
off. In the current spec, and as far as I know, Promises have always resolved
asynchronously. Synchronous resolution can lead to various problems including
running out of stack space and unintentional blocking code.
There's two mostly orthogonal concerns here. The first is the sync/async
issue:
console.log(1);
promise.resolve().then(() => {
console.log(2);
});
console.log(3);
Addon SDK Promises print 1, 2, 3. Every other Promise library prints 1,
3, 2. This introduces subtle timing dependencies that are very hard to
track down, as they tend to span across almost completely unrelated
code. It's very difficult to track down these bugs, but the changes are
usually quite minor in terms of amount of code changed.
The second concern is switching from Deferreds, which used in most
existing Promise libraries, to using the Promise constructor:
promises/a+:
let deferred = Promise.defer();
async(() => {
deferred.resolve();
});
return deferred.promise;
DOM Promises:
return new Promise((resolve, reject) => {
async(() => {
resolve();
});
});
This same conversion has to happen for code relying on either
Promise.jsm or Addon SDK Promises. It's an easy, mostly mechanical
change, but it involves touching a huge amount of code. This conversion
also requires the sync -> async conversion for Addon SDK Promises.
I think it makes sense to break these up, first doing the sync -> async
conversion and then doing the Deferred to Promise constructor
conversion. As soon as a given file has been converted to Promise.jsm it
can then be converted to DOM Promises, so these efforts can be done in
parallel as there is a lot of existing Promise.jsm usage in the tree.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform