fix: have setup hang until we have a connected peer

This commit is contained in:
Derrick Hammer 2023-09-02 12:44:04 -04:00
parent 6c76768fe0
commit dcc72b9cec
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 0 deletions

View File

@ -53,6 +53,8 @@ async function handlePresentKey(aq: ActiveQuery) {
async function setup() { async function setup() {
swarm = createSwarmClient(); swarm = createSwarmClient();
const peerConnectedDefer = defer();
const db = new Level<string, Uint8Array>("s5"); const db = new Level<string, Uint8Array>("s5");
await db.open(); await db.open();
let config = { let config = {
@ -90,7 +92,10 @@ async function setup() {
await s5peer.init(); await s5peer.init();
node.services.p2p.onNewPeer(s5peer, true); node.services.p2p.onNewPeer(s5peer, true);
peerConnectedDefer.resolve();
}); });
return peerConnectedDefer.promise;
} }
async function ready(aq: ActiveQuery) { async function ready(aq: ActiveQuery) {