本文整理匯總了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();
}
});