Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda