https://github.com/rangermauve/hypercore-really-ready
Waits for a hypercore to be _really_ ready. That is, that it's synced with peers and is good to go
https://github.com/rangermauve/hypercore-really-ready
Last synced: 14 days ago
JSON representation
Waits for a hypercore to be _really_ ready. That is, that it's synced with peers and is good to go
- Host: GitHub
- URL: https://github.com/rangermauve/hypercore-really-ready
- Owner: RangerMauve
- License: mit
- Created: 2020-03-25T00:15:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-25T00:47:09.000Z (about 5 years ago)
- Last Synced: 2025-04-19T12:05:06.220Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hypercore-really-ready
Waits for a hypercore to be _really_ ready. That is, that it's synced with peers and is good to goChecks for the following:
- Waits for the `ready` event to make sure internal stuff is initialized
- If the feed is writable, it's ready
- If you have peers, make sure you know what the latest index they know if is
- If you don't have peers, wait for them and update the indexYou should probably wrap this with a timeout for any user-facing application since there's a chance a feed will never get peers.
## Installing
```
npm install --save hypercore-really-ready
```## Example
```javascript
const reallyReady = require('hypercore-really-ready')// The feed is initialized and has synced with peers
// You might want to wrap this in a timeout
await reallyReady(feed)// If you have a hyperdrive, pass in its metadata feed
// This will make sure you don't get empty or outdated readdir calls
await reallyReady(hyperdrive.metadata)// You can also use callbacks if that's more your thing
reallyReady(feed, (err) => {
if(err) console.error(err)
else console.log('It's ready!')
})
```