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


TypeScript Tyr.sleepUntil方法代碼示例

本文整理匯總了TypeScript中tyranid.Tyr.sleepUntil方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tyr.sleepUntil方法的具體用法?TypeScript Tyr.sleepUntil怎麽用?TypeScript Tyr.sleepUntil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tyranid.Tyr的用法示例。


在下文中一共展示了Tyr.sleepUntil方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

    it('should let you define custom events', async () => {
      let count = 0;

      User.on({
        type: 'myCustomEvent',
        async handler(event) {
          count++;
        }
      });

      await User.fire({
        type: 'myCustomEvent'
      });

      await Tyr.sleepUntil(() => !!count);
    });
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:16,代碼來源:event.test.ts

示例2: it

      it('should support subscriptions', async () => {
        const cleanup = () =>
          Promise.all([
            Location.remove({ query: {} }),
            Subscription.remove({ query: {} })
          ]);

        await cleanup();

        try {
          await page.evaluate(`
const Location = Tyr.byName.location;
Location.subscribe({});
window._gotChangeEvent = false;
window._gotRemoveEvent = false;
Location.on({ type: 'change', handler(event) { window._gotChangeEvent = true; } });
Location.on({ type: 'update', handler(event) { window._gotUpdateEvent = true; } });
Location.on({ type: 'insert', handler(event) { window._gotInsertEvent = true; } });
Location.on({ type: 'remove', handler(event) { window._gotRemoveEvent = true; } });`);

          await Tyr.sleepUntil(async () =>
            Subscription.exists({
              query: { u: 1, c: Location.id }
            })
          );

          await Location.save({ name: 'Yosemite Valley' });

          await Tyr.sleepUntil(async () =>
            page.evaluate(
              `Tyr.byName.location.values.length === 1 && window._gotChangeEvent && window._gotInsertEvent && !window._gotUpdateEvent`
            )
          );

          await page.evaluate(`
          window._gotChangeEvent = false;
          window._gotUpdateEvent = false;
          window._gotInsertEvent = false;`);
          let location = await Location.findOne({
            query: { name: 'Yosemite Valley' }
          });
          location!.name = 'Yosemite Valley 2';
          await location!.$save();

          await Tyr.sleepUntil(async () =>
            page.evaluate(
              `Tyr.byName.location.values.length === 1 && Tyr.byName.location.values[0].name === 'Yosemite Valley 2' && window._gotChangeEvent && !window._gotInsertEvent && window._gotUpdateEvent`
            )
          );

          location = await Location.findOne({
            query: { name: 'Yosemite Valley 2' }
          });
          await location!.$remove();

          await Tyr.sleepUntil(async () =>
            page.evaluate(
              'Tyr.byName.location.values.length === 0 && window._gotRemoveEvent'
            )
          );
        } finally {
          await cleanup();
        }
      });
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:64,代碼來源:express.test.ts


注:本文中的tyranid.Tyr.sleepUntil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。