On Tuesday, November 19, 2013 10:48:24 AM UTC-8, Brandon Benvie wrote:> > 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.
Succinctly expressed and good point! It would be great if devs could hang off bugs from bug 939636 for known tests/implementations where the 'promise.js resolve() is synchronous' needs fixing to use the 'DOM Promise resolve() is always async', not doing which would break some code. Most code does not seem to be like that. My status: I've gotten a few places in dom/ and browser/ updated, but my current focus is to get toolkit/ up to speed to use DOM Promise exclusively. I've made progress on toolkit/modules/, where Task.jsm and Sqlite.jsm were slightly tricky. Will have patches up soon. Based on bholley's comments on bug 939636, chrome code will need to do Cu.importGlobalProperties(["Promise"]); to use DOM Promises. Nikhil _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform