Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!