I need to use this in my .js file but I have no idea how to make it javascript. Here's the function:
async function readLines(filename: string, processLine: (line: string) => Promise<void>): Promise<void> {
return new Promise((resolve, reject) => {
lineReader.eachLine(filename, (line, last, callback) => {
if (!callback) throw new Error('panic');
processLine(line)
.then(() => last ? resolve() : callback())
.catch(reject);
});
});
}
Now here's how I call it:
await readLines(filename, async (line) => {
await delay(1000)
some_other_func(line);
});
You just need to remove the parameter processLine type and the return value type.
async function readLines(filename, processLine) {
return new Promise((resolve, reject) => {
lineReader.eachLine(filename, (line, last, callback) => {
if (!callback) throw new Error('panic');
processLine(line)
.then(() => last ? resolve() : callback())
.catch(reject);
});
});
}