本文整理汇总了TypeScript中angular2/src/core/facade/async.PromiseWrapper.then方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PromiseWrapper.then方法的具体用法?TypeScript PromiseWrapper.then怎么用?TypeScript PromiseWrapper.then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/src/core/facade/async.PromiseWrapper
的用法示例。
在下文中一共展示了PromiseWrapper.then方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
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');
return null;
});
PromiseWrapper.then(all, (_) => {
allCalled = true;
async.done();
return null;
});
one.resolve('one');
}));
示例2: inject
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');
}));
示例3: expectResponse
function expectResponse(request: Promise<string>, url: string, response: string, done = null) {
function onResponse(text: string): string {
if (response === null) {
throw `Unexpected response ${url} -> ${text}`;
} else {
expect(text).toEqual(response);
if (isPresent(done)) done();
}
return text;
}
function onError(error: string): string {
if (response !== null) {
throw `Unexpected error ${url}`;
} else {
expect(error).toEqual(`Failed to load ${url}`);
if (isPresent(done)) done();
}
return error;
}
PromiseWrapper.then(request, onResponse, onError);
}