Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
Is there a way to translate this TypeScript piece to JavaScript in node.js?

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);
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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);
        });
    });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda