lets say we have library that reads file line by line like this:
var lines = lib.open('file.txt');
lines.on('line', function(line) {
console.log(line);
});
Is there any way to wrap the code and create generator that could be used with "for of" loop:
for (let line of lines) {
console.log(line);
}
lines.on('line', function(line) {
yield line; // doesnt work inside the function
console.log(line);
});
If i yield inside the function it doesn't work.
Thanks