本文整理汇总了TypeScript中rsvp.Promise类的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise类的具体用法?TypeScript Promise怎么用?TypeScript Promise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Promise类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: testHashSettled
function testHashSettled() {
function isFulfilled<T>(state: RSVP.PromiseState<T>): state is RSVP.Resolved<T> {
return state.state === RSVP.State.fulfilled;
}
let promises = {
myPromise: RSVP.Promise.resolve(1),
yourPromise: RSVP.Promise.resolve('2'),
theirPromise: RSVP.Promise.resolve({ key: 3 }),
notAPromise: 4,
};
RSVP.hashSettled(promises).then(function(hash) {
if (isFulfilled(hash.myPromise)) {
assertType<number>(hash.myPromise.value);
}
if (isFulfilled(hash.yourPromise)) {
assertType<string>(hash.yourPromise.value);
}
if (isFulfilled(hash.theirPromise)) {
assertType<{ key: number }>(hash.theirPromise.value);
}
if (isFulfilled(hash.notAPromise)) {
assertType<number>(hash.notAPromise.value);
}
});
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:25,代码来源:rsvp-tests.ts
示例2: testResolve
function testResolve() {
assertType<RSVP.Promise<void>>(RSVP.resolve());
assertType<RSVP.Promise<string>>(RSVP.resolve('this is a string'));
assertType<RSVP.Promise<string>>(RSVP.resolve(RSVP.resolve('nested')));
assertType<RSVP.Promise<string>>(RSVP.resolve(Promise.resolve('nested')));
let promise = RSVP.Promise.resolve(1);
let imported = resolve(1);
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:9,代码来源:rsvp-tests.ts
示例3: testCast
function testCast() {
RSVP.Promise.cast('foo').then(value => {
assertType<string>(value);
});
RSVP.cast(42).then(value => {
assertType<number>(value);
});
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:9,代码来源:rsvp-tests.ts
示例4: TransitionState
.then(function(result: TransitionState<Route>) {
let models = [];
for (let i = 0; i < result.routeInfos.length; i++) {
models.push(result.routeInfos[i].context);
}
assert.equal(models[0], fooModel);
assert.equal(models[1], barModel);
return Promise.resolve(new TransitionState());
})
开发者ID:tildeio,项目名称:router.js,代码行数:10,代码来源:transition_state_test.ts
示例5: testReject
function testReject() {
assertType<RSVP.Promise<never>>(RSVP.reject());
assertType<RSVP.Promise<never>>(RSVP.reject('this is a string'));
RSVP.reject({ ok: false }).catch(reason => {
console.log(`${reason} could be anything`);
});
RSVP.reject({ ok: false }, 'some label').catch((reason: any) => reason.ok);
let promise = RSVP.Promise.reject(new Error('WHOOPS'));
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:11,代码来源:rsvp-tests.ts
示例6: testRace
function testRace() {
const imported = race([]);
const firstPromise = RSVP.race([{ notAPromise: true }, RSVP.resolve({ some: 'value' })]);
assertType<RSVP.Promise<{ notAPromise: boolean } | { some: string }>>(firstPromise);
let promise1 = RSVP.resolve(1);
let promise2 = RSVP.resolve('2');
RSVP.Promise.race([promise1, promise2], 'my label').then(function(result) {
assertType<string | number>(result);
});
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:11,代码来源:rsvp-tests.ts
示例7:
(() => {
if (err === null) {
return this.pageModel.ajax<any>(
'POST',
this.pageModel.createActionUrl('/subcorpus/subcorp', [['format', 'json']]),
args
);
} else {
return RSVP.Promise.reject(err);
}
})().then(
开发者ID:czcorpus,项目名称:kontext,代码行数:12,代码来源:withinForm.ts
示例8: submit
submit():RSVP.Promise<any> {
const args = this.getSubmitArgs();
const err = this.validateForm(true);
if (err === null) {
return this.pageModel.ajax<any>(
'POST',
this.pageModel.createActionUrl('/subcorpus/subcorp', [['format', 'json']]),
args
);
} else {
return RSVP.Promise.reject(err);
}
}
开发者ID:czcorpus,项目名称:kontext,代码行数:14,代码来源:form.ts
示例9: testAll
function testAll() {
const imported = all([]);
const empty = RSVP.Promise.all([]);
const everyPromise = RSVP.all([
'string',
RSVP.resolve(42),
RSVP.resolve({ hash: 'with values' }),
]);
assertType<RSVP.Promise<[string, number, { hash: string }]>>(everyPromise);
const anyFailure = RSVP.all([12, 'strings', RSVP.reject('anywhere')]);
assertType<RSVP.Promise<{}>>(anyFailure);
let promise1 = RSVP.resolve(1);
let promise2 = RSVP.resolve('2');
let promise3 = RSVP.resolve({ key: 13 });
RSVP.Promise.all([promise1, promise2, promise3], 'my label').then(function(array) {
assertType<number>(array[0]);
assertType<string>(array[1]);
assertType<{ key: number }>(array[2]);
});
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:24,代码来源:rsvp-tests.ts
示例10: present
/**
Creates an "owner" (an object that either _is_ or duck-types like an
`Ember.ApplicationInstance`) from the provided options.
If `options.application` is present (e.g. setup by an earlier call to
`setApplication`) an `Ember.ApplicationInstance` is built via
`application.buildInstance()`.
If `options.application` is not present, we fall back to using
`options.resolver` instead (setup via `setResolver`). This creates a mock
"owner" by using a custom created combination of `Ember.Registry`,
`Ember.Container`, `Ember._ContainerProxyMixin`, and
`Ember._RegistryProxyMixin`.
@private
@param {Ember.Application} [application] the Ember.Application to build an instance from
@param {Ember.Resolver} [resolver] the resolver to use to back a "mock owner"
@returns {Promise<Ember.ApplicationInstance>} a promise resolving to the generated "owner"
*/
export default function buildOwner(
application: Application | undefined | null,
resolver: Resolver | undefined | null
): Promise<Owner> {
if (application) {
return (application.boot().then(app => app.buildInstance().boot()) as unknown) as Promise<
Owner
>;
}
if (!resolver) {
throw new Error(
'You must set up the ember-test-helpers environment with either `setResolver` or `setApplication` before running any tests.'
);
}
let { owner } = legacyBuildRegistry(resolver) as { owner: Owner };
return Promise.resolve(owner);
}
开发者ID:switchfly,项目名称:ember-test-helpers,代码行数:38,代码来源:build-owner.ts
注:本文中的rsvp.Promise类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论