This is a typical situation in node.js:
asyncFunction(arguments, callback);
When asynFunction
completes, callback
gets called. A problem I see with this pattern is that, if asyncFunction
never completes (and asynFunction
doesn't have a built-in time-out system) then callback
will never be called. Worse, it seems that callback
has no way of determining that asynFunction
will never return.
I want to implement a "timeout" whereby if callback
has not been called by asyncFunction
within 1 second, then callback
automatically gets called with the assumption that asynFunction
has errored out. What is the standard way of doing this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…