-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
It would be nice if LineReader supported promises. Here is a class that wraps the newLine method with a promise and an example of how useful it is.
const LineReader = require('node-line-reader').LineReader;
class Reader {
constructor(file) {
this.reader = new LineReader(file);
}
nextLine() {
return new Promise((resolve, reject) => {
this.reader.nextLine((err, line) => {
if (err) return reject(err);
resolve(line);
});
});
}
}
async function main() {
let reader = new Reader('nextline.js');
for (let i = 1; i < 1000; i++) {
let line = await reader.nextLine();
if (line === null) break;
console.log('', i, line);
}
}
main();
msaari
Metadata
Metadata
Assignees
Labels
No labels