Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
sample: refactor async iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Oct 7, 2019
1 parent f134854 commit 6704eab
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions samples/async.iterator.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

const assert = require('assert')
const parse = require('..')
const generate = require('csv-generate')

const main = async function(){
// Initialise the parser by generating random records
const parser = generate({
(async () => {
const assert = require('assert')
const parse = require('..')
const generate = require('csv-generate')
// Create a readable input stream, could be `fs.createReadStream`
const input = generate({
length: 10000
})
.pipe(parse())
// Initialise the parser by generating random records
const parser = input.pipe(parse())
// Iterate through each records
let count = 0
for await (const record of parser) {
count++
}
// Validation
assert.strictEqual(count, 10000)
}
main()
})();

0 comments on commit 6704eab

Please sign in to comment.