When I set a new setTimeout in the form:
async function run(price){
...
await setTimeout(
async function run(val) {
await foo(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 run(price){
...
await setTimeout(
async function run(val) {
await foo(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. Note that this error is only thrown when I call await run(x)
from inside a bunch of nested then’s and async (arg) => {< >}
codeblocks, 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!