js-waku/packages/tests/src/waitForConnections.ts
Danish Arora 7affbe222d
feat: lightpush & filter send requests to multiple peers (#1779)
* feat: lightpush & filter send requests to multiple peers

* build message-hash before core

* chore: restructure folder heirrarchy

* fix: imports

* chore: move @waku/core to dev deps

* feat: create a new `ServiceNodes` wrapper class to encapsulate service node and message collector with redundancy accounted for

* chore(filter): move tests against single service node to a subdir

* feat: support relay, add strict checking, add tests

* fix(filter): handle errors

* chore(tests): add tests for ping

* add tests for push

* chore: abstract redundancy

* feat: add unsubscribe tests

* fix: tests

* add lightpush tests

* fix: imports

* fix: merge & add warning

* merge: master

* fix: breaking tests with master

* address comments

* make num peers configurable

* fix: typo
2024-01-24 18:24:03 +05:30

21 lines
555 B
TypeScript

import type { LightNode } from "@waku/interfaces";
export async function waitForConnections(
numPeers: number,
waku: LightNode
): Promise<void> {
let connectionsLen = waku.libp2p.getConnections().length;
if (connectionsLen >= numPeers) {
return;
}
await new Promise<void>((resolve) => {
const cb = (): void => {
connectionsLen++;
if (connectionsLen >= numPeers) {
waku.libp2p.removeEventListener("peer:identify", cb);
resolve();
}
};
waku.libp2p.addEventListener("peer:identify", cb);
});
}