本文整理匯總了TypeScript中rsvp.Promise.resolve方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise.resolve方法的具體用法?TypeScript Promise.resolve怎麽用?TypeScript Promise.resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsvp.Promise
的用法示例。
在下文中一共展示了Promise.resolve方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
});
}
示例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);
}
示例3: 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());
})
示例4: 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);
}
示例5: function
getHandler: function(name: string) {
return Promise.resolve(handlers[name] || (handlers[name] = createHandler('empty')));
},
示例6: keepGoing
function keepGoing() {
assert.ok(true, 'continuation function was called');
return Promise.resolve(false);
}
示例7: noop
function noop() {
return Promise.resolve(false);
}
示例8: Error
import RSVP from 'rsvp';
let promise1: RSVP.Promise<number, Error> = RSVP.Promise.resolve(1);
let promise1a: RSVP.Promise<number, Error> = RSVP.resolve(1);
let promise2: RSVP.Promise<number, Error> = RSVP.Promise.resolve(2);
let promise3: RSVP.Promise<number, Error> = RSVP.Promise.reject(new Error('3'));
let promise3a: RSVP.Promise<number, Error> = RSVP.reject(new Error('3'));
let promiseArray = [promise1, promise2, promise3];
let promiseHash = {
promiseA: promise1,
promiseB: promise2,
promiseC: promise3,
notAPromise: 4,
};
RSVP.Promise.all(promiseArray).then(arr => {}, err => {});
RSVP.all(promiseArray).then(arr => {}, err => {});
RSVP.Promise.race(promiseArray).then(arr => {}, err => {});
RSVP.race(promiseArray).then(arr => {}, err => {});
RSVP.allSettled(promiseArray).then(arr => {}, err => {});
let deferred = RSVP.defer();
deferred.resolve('Success');
deferred.promise.then(value => {});
示例9: fillOut
// eslint-disable-next-line require-jsdoc
function fillOut(element: FormControl, text: string, delay: number) {
const inputFunctions = text.split('').map(character => keyEntry(element, character));
return inputFunctions.reduce((currentPromise, func) => {
return currentPromise.then(() => delayedExecute(delay)).then(func);
}, Promise.resolve(undefined));
}