Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accountCounter method for blockchain prototype
- Loading branch information
1 parent
7eedf33
commit 80863a3
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |