juandopazo/yui3 — pull request #3 by juandopazo (2013-01-04 02:02:39+00:00)
Title: Initial rewrite for compatibility with A+

This pull request is for discussing an alternate implementation that doesn't use Deferreds and has full compatibility with [promises-aplus](http://github.com/promises-aplus).

Main differences:

1. Y.defer is gone. Instead the proposed way of using promises is `Y.Promise(function (resolve, reject) {});`. This is compatible with Microsoft's implementation in WinJS and it's very nice in that it's really easy to create custom Promise objects. Just extend Y.Promise.

2. Only one value is allowed to be returned from promises. This simplifies a lot of code and it's easier to think about. The con is that Y.batch can't have named parameters for each operation.

3. Throwing inside a callback rejects the promise

4. Compatibility with A+ required that when returning a promise from a callback in `then`, `then` must be called on the new promise because A+ doesn't recognize `getStatus`.

5. `this` inside callbacks is now `undefined`.

Total concealment of the Resolver would be very easy. I went with a gentleman's private because of conversations with @lsmith and for easier debugging. It is a full circular reference, which I don't know what consequences might have in memory usage. Modern engines should handle them without issue.

I still haven't ported the test suite to YUI Test. It'd be nice to see if we could use Domenic's tests without losing code coverage reporting. Also, Domenic's tests are taking 9 seconds on my PC. That's really slow. I'm guessing it has to do with the number of `setTimeout(fn, 100)` that it's using.