本文整理汇总了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);
});
示例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();
}
});