fix(facade): Make PromiseWrapper#all semantics equivalent
The semantics between ES6 `Promise#all` and Dart's `Future#wait` are different for values that are not `Promise`/`Future`s. In ES6, non-`Promise` values are immediately completed to their current value. In Dart, non-`Future` values cause an error. Updated Dart's `PromiseWrapper#all` implementation to conform to the ES6 spec.
This commit is contained in:
@ -14,6 +14,7 @@ import {
|
||||
} from 'angular2/test_lib';
|
||||
|
||||
import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
export function main() {
|
||||
describe('EventEmitter', () => {
|
||||
@ -62,4 +63,45 @@ export function main() {
|
||||
// should call dispose on the subscription on throw
|
||||
// should call dispose on the subscription on return
|
||||
});
|
||||
}
|
||||
|
||||
// See ECMAScript 6 Spec 25.4.4.1
|
||||
describe("PromiseWrapper", () => {
|
||||
describe("#all", () => {
|
||||
it("should combine lists of Promises", inject([AsyncTestCompleter], (async) => {
|
||||
var one = PromiseWrapper.completer();
|
||||
var two = PromiseWrapper.completer();
|
||||
|
||||
var all = PromiseWrapper.all([one.promise, two.promise]);
|
||||
var allCalled = false;
|
||||
|
||||
PromiseWrapper.then(one.promise, (_) => {
|
||||
expect(allCalled).toBe(false);
|
||||
two.resolve('two');
|
||||
});
|
||||
|
||||
PromiseWrapper.then(all, (_) => {
|
||||
allCalled = true;
|
||||
async.done();
|
||||
});
|
||||
|
||||
one.resolve('one');
|
||||
}));
|
||||
|
||||
ListWrapper.forEach([null, true, false, 10, 'thing', {}, []], (abruptCompletion) => {
|
||||
it(`should treat "${abruptCompletion}" as an "abrupt completion"`,
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var one = PromiseWrapper.completer();
|
||||
|
||||
var all = PromiseWrapper.all([one.promise, abruptCompletion]);
|
||||
|
||||
PromiseWrapper.then(all, (val) => {
|
||||
expect(val[1]).toEqual(abruptCompletion);
|
||||
async.done();
|
||||
});
|
||||
|
||||
one.resolve('one');
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user