On 7/30/2013 1:41 PM, Boris Zbarsky wrote:
On 7/30/13 1:37 PM, Gavin Sharp wrote:
We'll need to investigate whether the implementations
are compatible, though

That's fair. DOM Promises are definitely modeled after Promises/A+, but the APIs might not quite match up. :(

They don't. With DOM Promises you might do:

    function doAsync(){
      return new Promise(function(resolver) {
        somethingRemote(function(err, result) {
          if (err) {
            resolver.reject(err);
          } else {
            resolver.resolve(result);
          }
        });
      });
    }

With the Promise implementation used in Addon SDK and devtools (and perhaps elsewhere), you would do:

    function doAsync(){
      let deferred = Promise.defer();
      somethingRemote(function(err, result){
        if (err) {
          deferred.reject(err);
        } else {
          deferred.resolve(result);
        }
      });
      return deferred.promise;
    }


It's not a transformation that can be done mechanically really. On the other hand, it's pretty trivial to wrap the DOM Promise API in an API that would be compatible with the old Promise implementation.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to