當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript rsvp.Promise類代碼示例

本文整理匯總了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;未經允許,請勿轉載。