mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
make polling function a global function
This commit is contained in:
@@ -15,6 +15,23 @@ ya+yfGi3g2ZUv6hrfe+j08ytekPHjXS0qzJoVELzKHa6EL9YAoZDXBtB6h+fGhXe
|
||||
SOcONbaf
|
||||
-----END PRIVATE KEY-----`
|
||||
|
||||
/**
|
||||
* Wait for a condition to become true until the timeout
|
||||
* is hit.
|
||||
* @param condition
|
||||
* @param timeout
|
||||
* @param interval
|
||||
*/
|
||||
async function waitForCondition(condition: () => boolean, timeout = 5000, interval = 500) {
|
||||
const startTime = Date.now();
|
||||
while (!condition()) {
|
||||
if (Date.now() - startTime > timeout) {
|
||||
throw new Error("Timeout waiting for condition");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||
}
|
||||
}
|
||||
|
||||
describe("NotificationService", () => {
|
||||
let repository: UnoptimizedInMemoryRepository
|
||||
let notificationService: NotificationService;
|
||||
@@ -98,15 +115,6 @@ describe("NotificationService", () => {
|
||||
// Assert
|
||||
// Because repository publisher calls subscriber without await
|
||||
// wait for the change to occur first
|
||||
async function waitForCondition(condition: () => boolean, timeout = 5000, interval = 500) {
|
||||
const startTime = Date.now();
|
||||
while (!condition()) {
|
||||
if (Date.now() - startTime > timeout) {
|
||||
throw new Error("Timeout waiting for condition");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||
}
|
||||
}
|
||||
|
||||
await waitForCondition(() => !notificationService.isNotificationScheduled(notificationData1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user