A way to support waiting/success/failed ternary
What I find missing in this lib is a failCondition, let say a new signature like:
holdUp(condition, [timeoutInterval], [retryInterval], [failCondition])
My usecase: I'm waiting from a global function to be loaded from another module so I call:
await holdUp(
() => whatever,
30000,
);
However is possible that this additional module will not be loaded at all. So I don't need to wait for 30 secs timeout to know that the function will not be there as I have a way to know it from the beginning (or few millisecs after).
In this case the current implementation will still wait for 30 secs, and I'll get a general Timeout.
What I'm thinking: a new failCondition function, still checked every retryInterval, but when truthy will immediately terminate waiting.
Hum, this is an interesting use case...
Maybe providing something like a signal to cancel it would do it?
function check(task) {
if (something) task.fail()
}
await holdUp(check, 3000)
Then you could also do things like:
const task = await holdUp(check, 3000)
if (something) task.fail()
What do you think?
That's would be an elegant solution! 👍