为node.js回调实现超时

为node.js回调实现超时,第1张

为node.js回调实现超时

我不熟悉执行此 *** 作的任何库,但连接起来并不难。

// Setup the timeout handlervar timeoutProtect = setTimeout(function() {  // Clear the local timer variable, indicating the timeout has been triggered.  timeoutProtect = null;  // Execute the callback with an error argument.  callback({error:'async timed out'});}, 5000);// Call the async functionasyncFunction(arguments, function() {  // Proceed only if the timeout handler has not yet fired.  if (timeoutProtect) {    // Clear the scheduled timeout handler    clearTimeout(timeoutProtect);    // Run the real callback.    callback();  }});


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4945010.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存