mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 14:34:19 +01:00
Remove findingPeers() & some flush() flow from hyperswarm examples (#176)
`swarm.flush()` was kept in scenarios where replicating a hypercore immediately was required.
This commit is contained in:
@@ -128,11 +128,8 @@ const mirror = debounce(mirrorDrive)
|
|||||||
// to the Hypercore instance of the hyperdrive
|
// to the Hypercore instance of the hyperdrive
|
||||||
drive.core.on('append', mirror)
|
drive.core.on('append', mirror)
|
||||||
|
|
||||||
const foundPeers = store.findingPeers()
|
|
||||||
|
|
||||||
// join a topic
|
// join a topic
|
||||||
swarm.join(drive.discoveryKey, { client: true, server: false })
|
swarm.join(drive.discoveryKey, { client: true, server: false })
|
||||||
swarm.flush().then(() => foundPeers())
|
|
||||||
|
|
||||||
// start the mirroring process (i.e copying the contents from remote drive to local dir)
|
// start the mirroring process (i.e copying the contents from remote drive to local dir)
|
||||||
mirror()
|
mirror()
|
||||||
@@ -198,9 +195,8 @@ const bee = new Hyperbee(core, {
|
|||||||
// wait till the properties of the hypercore instance are initialized
|
// wait till the properties of the hypercore instance are initialized
|
||||||
await core.ready()
|
await core.ready()
|
||||||
|
|
||||||
const foundPeers = store.findingPeers()
|
|
||||||
swarm.join(core.discoveryKey)
|
swarm.join(core.discoveryKey)
|
||||||
swarm.flush().then(() => foundPeers())
|
await swarm.flush()
|
||||||
|
|
||||||
// execute the listBee function whenever the data is appended to the underlying hypercore
|
// execute the listBee function whenever the data is appended to the underlying hypercore
|
||||||
core.on('append', listBee)
|
core.on('append', listBee)
|
||||||
|
|||||||
@@ -78,18 +78,12 @@ Pear.teardown(() => swarm.destroy())
|
|||||||
const core = new Hypercore(path.join(Pear.config.storage, 'reader-storage'), Pear.config.args[0])
|
const core = new Hypercore(path.join(Pear.config.storage, 'reader-storage'), Pear.config.args[0])
|
||||||
await core.ready()
|
await core.ready()
|
||||||
|
|
||||||
const foundPeers = core.findingPeers()
|
|
||||||
swarm.join(core.discoveryKey)
|
swarm.join(core.discoveryKey)
|
||||||
swarm.on('connection', conn => core.replicate(conn))
|
swarm.on('connection', conn => core.replicate(conn))
|
||||||
|
|
||||||
// swarm.flush() will wait until *all* discoverable peers have been connected to
|
// swarm.flush() will wait until *all* discoverable peers have been connected to
|
||||||
// It might take a while, so don't await it
|
await swarm.flush()
|
||||||
// Instead, use core.findingPeers() to mark when the discovery process is completed
|
|
||||||
swarm.flush().then(() => foundPeers())
|
|
||||||
|
|
||||||
// This won't resolve until either
|
|
||||||
// a) the first peer is found
|
|
||||||
// or b) no peers could be found
|
|
||||||
await core.update()
|
await core.update()
|
||||||
|
|
||||||
let position = core.length
|
let position = core.length
|
||||||
|
|||||||
@@ -192,10 +192,9 @@ const core = store.get({ key: b4a.from(key, 'hex') })
|
|||||||
// wait till the properties of the hypercore instance are initialized
|
// wait till the properties of the hypercore instance are initialized
|
||||||
await core.ready()
|
await core.ready()
|
||||||
|
|
||||||
const foundPeers = store.findingPeers()
|
|
||||||
// join a topic
|
// join a topic
|
||||||
swarm.join(core.discoveryKey)
|
swarm.join(core.discoveryKey)
|
||||||
swarm.flush().then(() => foundPeers())
|
await swarm.flush()
|
||||||
|
|
||||||
// update the meta-data information of the hypercore instance
|
// update the meta-data information of the hypercore instance
|
||||||
await core.update()
|
await core.update()
|
||||||
|
|||||||
@@ -100,9 +100,8 @@ const core = store.get({ key, valueEncoding: 'json' })
|
|||||||
// wait till all the properties of the hypercore instance are initialized
|
// wait till all the properties of the hypercore instance are initialized
|
||||||
await core.ready()
|
await core.ready()
|
||||||
|
|
||||||
const foundPeers = core.findingPeers()
|
|
||||||
swarm.join(core.discoveryKey)
|
swarm.join(core.discoveryKey)
|
||||||
swarm.flush().then(() => foundPeers())
|
await swarm.flush()
|
||||||
|
|
||||||
// update the meta-data of the hypercore instance
|
// update the meta-data of the hypercore instance
|
||||||
await core.update()
|
await core.update()
|
||||||
|
|||||||
Reference in New Issue
Block a user