aboutsummaryrefslogtreecommitdiff
path: root/node_modules/async/timeout.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-24 15:10:37 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-24 15:11:17 +0200
commit7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch)
tree70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/async/timeout.js
parentaca1143cb9eed16cf37f04e475e4257418dd18ac (diff)
fix build issues and add typedoc
Diffstat (limited to 'node_modules/async/timeout.js')
-rw-r--r--node_modules/async/timeout.js41
1 files changed, 20 insertions, 21 deletions
diff --git a/node_modules/async/timeout.js b/node_modules/async/timeout.js
index 39fdc07c3..b5cb505eb 100644
--- a/node_modules/async/timeout.js
+++ b/node_modules/async/timeout.js
@@ -57,34 +57,33 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* });
*/
function timeout(asyncFn, milliseconds, info) {
- var originalCallback, timer;
- var timedOut = false;
+ var fn = (0, _wrapAsync2.default)(asyncFn);
- function injectedCallback() {
- if (!timedOut) {
- originalCallback.apply(null, arguments);
- clearTimeout(timer);
- }
- }
+ return (0, _initialParams2.default)(function (args, callback) {
+ var timedOut = false;
+ var timer;
- function timeoutCallback() {
- var name = asyncFn.name || 'anonymous';
- var error = new Error('Callback function "' + name + '" timed out.');
- error.code = 'ETIMEDOUT';
- if (info) {
- error.info = info;
+ function timeoutCallback() {
+ var name = asyncFn.name || 'anonymous';
+ var error = new Error('Callback function "' + name + '" timed out.');
+ error.code = 'ETIMEDOUT';
+ if (info) {
+ error.info = info;
+ }
+ timedOut = true;
+ callback(error);
}
- timedOut = true;
- originalCallback(error);
- }
- var fn = (0, _wrapAsync2.default)(asyncFn);
+ args.push(function () {
+ if (!timedOut) {
+ callback.apply(null, arguments);
+ clearTimeout(timer);
+ }
+ });
- return (0, _initialParams2.default)(function (args, origCallback) {
- originalCallback = origCallback;
// setup timer and call original function
timer = setTimeout(timeoutCallback, milliseconds);
- fn.apply(null, args.concat(injectedCallback));
+ fn.apply(null, args);
});
}
module.exports = exports['default']; \ No newline at end of file