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

95
Visualizações
setTimeout asks for object then gets ignored

When I set a new setTimeout in the form:

async function someFn(price){
...
    await setTimeout(
      async function run(val) {
        await someFn(val);
      },
      delay,
      price
    );
}

, I get the error

node:internal/errors:464                                                                                                       
    ErrorCaptureStackTrace(err);                                                                                               
    ^                                                                                                                          
                                                                                                                               
TypeError [ERR_INVALID_ARG_TYPE]: The "options" argument must be of type object. Received type number (135.83422382)           
    at new NodeError (node:internal/errors:371:5)                                                                              
    at setTimeout (node:timers/promises:46:7)

so I change it to

async function someFn(price){
...
    await setTimeout(
      async function run(val) {
        await someFn(val[0]);
      },
      delay,
      [price]
    );
}

and the error is gone all of a sudden. The error is also not thrown when price is a string, which is weird since string should also be a primitive type. The final weirdest thing is that after this array fix, the function inside the setTimeout is fully ignored when the code runs (a console log before and after prints).

Note that this error is only thrown when I call await someFn(x) from inside a bunch of nested .then(async (arg) => {<code>}) blocks, but not when the await run(x) is on its own. This is overall the weirdest error I've ever seen, and I'd appreciate some guidance!

about 4 years ago · Juan Pablo Isaza
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