There is a asynchronous function fun(param, callback)
like this:
fun(param, function(err){
if(err) console.log(err);
doSomething();
});
How do I set a time limit to run this function?
For example, I set time limit equals to 10 secs.
If it finish in 10 seconds, there is no error.
If it run exceed 10 seconds, terminate it and show error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…