*Remove peer1 connection listener after broadcast
This commit is contained in:
parent
ce1854de83
commit
fcfdd51908
9
test.js
9
test.js
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue