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!