*Remove peer1 connection listener after broadcast

This commit is contained in:
Derrick Hammer 2022-11-27 03:36:42 -05:00
parent ce1854de83
commit fcfdd51908
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 5 deletions

View File

@ -32,15 +32,14 @@ test('Broadcast through several peers', (t) => {
t.deepEquals(message, data, 'Data got broadcast') t.deepEquals(message, data, 'Data got broadcast')
}) })
function maybeFlood () { function maybeFlood() {
if (peer1.peers.size === 2) { if (peer1.peers.size === 2) {
flood1.broadcast(data) flood1.broadcast(data);
peer1.removeListener("connection", maybeFlood);
} }
} }
peer1.on('connection', () => { peer1.on("connection", maybeFlood);
maybeFlood()
})
t.teardown(() => { t.teardown(() => {
[peer1, peer2, peer3].forEach((item) => item.destroy()) [peer1, peer2, peer3].forEach((item) => item.destroy())