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

92
Vistas
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 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