本文整理汇总了TypeScript中angular2/src/core/facade/async.PromiseWrapper类的典型用法代码示例。如果您正苦于以下问题:TypeScript PromiseWrapper类的具体用法?TypeScript PromiseWrapper怎么用?TypeScript PromiseWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PromiseWrapper类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: macroTask
macroTask(() => {
logOnError();
var c: PromiseCompleter<any> = PromiseWrapper.completer();
_zone.run(() => {
TimerWrapper.setTimeout(() => {
TimerWrapper.setTimeout(() => {
c.resolve(null);
throw new BaseException('ccc');
}, 0);
}, 0);
});
c.promise.then((_) => {
expect(_traces.length).toBe(1);
expect(_traces[0].length).toBeGreaterThan(1);
async.done();
});
});
开发者ID:hankduan,项目名称:angular,代码行数:19,代码来源:ng_zone_spec.ts
示例2: macroTask
macroTask(() => {
_zone.overrideOnErrorHandler(logError);
var c: PromiseCompleter<any> = PromiseWrapper.completer();
_zone.run(() => {
microTask(() => {
microTask(() => {
c.resolve(null);
throw new BaseException("ddd");
});
});
});
c.promise.then((_) => {
expect(_traces.length).toBe(1);
expect(_traces[0].length).toBeGreaterThan(1);
async.done();
});
});
开发者ID:hankduan,项目名称:angular,代码行数:19,代码来源:ng_zone_DEPRECATED_spec.ts
示例3: sample
sample({id, execute, prepare, microMetrics, bindings}): Promise<SampleState> {
var sampleBindings = [
_DEFAULT_PROVIDERS,
this._defaultBindings,
bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute)
];
if (isPresent(prepare)) {
sampleBindings.push(bind(Options.PREPARE).toValue(prepare));
}
if (isPresent(microMetrics)) {
sampleBindings.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
}
if (isPresent(bindings)) {
sampleBindings.push(bindings);
}
var inj = Injector.resolveAndCreate(sampleBindings);
var adapter = inj.get(WebDriverAdapter);
return PromiseWrapper
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
.then((args) => {
var capabilities = args[0];
var userAgent = args[1];
// This might still create instances twice. We are creating a new injector with all the
// providers.
// Only WebDriverAdapter is reused.
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better.
var injector = Injector.resolveAndCreate([
sampleBindings,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);
return sampler.sample();
});
}
开发者ID:hankduan,项目名称:angular,代码行数:42,代码来源:runner.ts
示例4: 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);
}
开发者ID:hankduan,项目名称:angular,代码行数:23,代码来源:xhr_mock_spec.ts
示例5:
promise = PromiseWrapper.resolve(4).then((x) => PromiseWrapper.resolve(x));
开发者ID:hankduan,项目名称:angular,代码行数:1,代码来源:ng_zone_spec.ts
示例6: microTask
// Schedules a microtasks (using a resolved promise .then())
function microTask(fn: Function): void {
PromiseWrapper.resolve(null).then((_) => { fn(); });
}
开发者ID:hankduan,项目名称:angular,代码行数:4,代码来源:ng_zone_spec.ts
示例7: executeScript
executeScript(script): Promise<string> { return PromiseWrapper.resolve('someUserAgent'); }
开发者ID:hankduan,项目名称:angular,代码行数:1,代码来源:runner_spec.ts
示例8: executeScript
executeScript(script) {
this._log.push(['executeScript', script]);
return PromiseWrapper.resolve(null);
}
开发者ID:hankduan,项目名称:angular,代码行数:4,代码来源:chrome_driver_extension_spec.ts
示例9: expect
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
expect(arg1).toEqual(PASSED_ARG_1);
return PromiseWrapper.wrap(() => { return RESULT; });
});
开发者ID:hankduan,项目名称:angular,代码行数:4,代码来源:service_message_broker_spec.ts
注:本文中的angular2/src/core/facade/async.PromiseWrapper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论