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

109
Visualizações
Syntax of process.nextTick - arguments passed

I was learning about process.nextTick and playing around with it. Got a small doubt regarding that itself. The first argument of process.nextTick is a callback function, what is the second or third argument? Consider the following code: This is printing error on console but not printing "First line" console.log value -

function promise(value, cb) {
    if (typeof value !== 'string') {
        return cb(new TypeError('Value should be string'));
    }
    cb(null, Promise.resolve('Hello'));
}

promise(1, (err, success) => {
    if (err) throw err;
    success.then((res) => console.log(res));
});

console.log('First line');

I tried to correct it using the following code using process.nextTick and it prints "First line" console on the terminal and then the error, which is fine, understandable but I had to pass the callback function and the error to process.nextTick. Is that how it works? Can someone maybe give a better explanation about that? I'm talking about the syntax and number of arguments of process.nextTick here, to be specific -

function promise(value, cb) {
    if (typeof value !== 'string') {
        return process.nextTick(cb,
            new TypeError('Value should be string'));
    }
    cb(null, Promise.resolve('Hello'));
}

promise(1, (err, success) => {
    if (err) throw err;
    success.then((res) => console.log(res));
});

console.log('First line');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Docs is pretty clear:

process.nextTick(callback[, ...args])

  • callback <Function>

  • ...args <any> Additional arguments to pass when invoking the callback

That's how the method works, it takes a callback and optional args to pass to the callback when invoked.

https://nodejs.org/api/process.html#processnexttickcallback-args

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