Necesito usar esto en mi archivo .js pero no tengo idea de cómo hacerlo javascript. Aquí está la función:
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); }); }); }Ahora así es como lo llamo:
await readLines(filename, async (line) => { await delay(1000) some_other_func(line); });Solo necesita eliminar el tipo de parámetro processLine y el tipo de valor devuelto.
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); }); }); }