Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@robertkowalski
Created September 2, 2020 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertkowalski/884f7855499ddd702e4c137081234a1c to your computer and use it in GitHub Desktop.
Save robertkowalski/884f7855499ddd702e4c137081234a1c to your computer and use it in GitHub Desktop.
'use strict'
process.env.DEBUG = process.env.DEBUG || 'bfx:*'
const path = require('path')
const Hyperbee = require('hyperbee')
const hypercore = require('hypercore')
const replicate = require('@hyperswarm/replicator')
const hopts = {
overwrite: true
}
const hbOpts = {
valueEncoding: 'json',
keyEncoding: 'utf-8'
}
const feed = hypercore(path.join(__dirname, 'dbs', 'BTCUSD'), hopts)
const db = new Hyperbee(feed, hbOpts)
const replication = replicate(feed, { announce: true, live: true, lookup: false })
db.feed.ready(next)
async function next () {
const stream = db.createHistoryStream({
gte: 10,
live: true
})
const batch = db.batch()
for (let i = 0; i < 1000; i++) {
await batch.put(i + '', null)
}
await batch.flush()
for await (const data of stream) {
const { key, value } = data
if (key === '999') {
console.log("BREAK")
break;
}
}
console.log("continue")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment