Created
September 2, 2020 11:07
-
-
Save robertkowalski/884f7855499ddd702e4c137081234a1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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