Skip to content

Commit

Permalink
Add accountCounter method for blockchain prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
gigatoride committed Jun 7, 2019
1 parent 7eedf33 commit 80863a3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/blockchain/accountCounter.js
@@ -0,0 +1,27 @@
const iteratorStream = require('async-iterator-to-stream');
const api = require('../helper');
const { sleep } = require('../utils');

/**
* Stream account counter
* @returns {Stream.<Number>} - account number
* @memberof Scan.blockchain
*/
function accountCounter() {
let latestCatch;
const iterator = async function * (ms = 700) {
while (true) {
const count = await api.getAccountCount();
if (count && latestCatch !== count) {
latestCatch = count;
yield count;
}

await sleep(ms);
}
};

return iteratorStream.obj(iterator());
}

module.exports = accountCounter;

0 comments on commit 80863a3

Please sign in to comment.