I have a long running function call and I want to limit its execution time.
function f(a,b,c) {
// some long-running code
return value;
}
var val = f(a,b,c); // this call should be limited to x milliseconds
// if the function doesn't return we continue with a fall-back value (which is available in the calling method)
How can I call this code with a timeout, so that if the execution finishes it will return value
and otherwise it will return a default value?
I found this question but it's 9 years old and I couldn't get the most recent answer (the one using Promises) modified for my use-case. Is there a simpler way to achieve this?