summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Argasinski <argasinski.hubert@gmail.com>2016-08-06 21:30:50 -0400
committerHubert Argasinski <argasinski.hubert@gmail.com>2016-08-06 21:30:50 -0400
commit8ea5ea8b9a229882e82e08287bb68a28fd4ecd2f (patch)
tree258a61d8c353deab67b98d3496dfd77de354bd59
parent6f19a8d5219c516b765a30e243ead0e590ca1a5c (diff)
downloadasync-8ea5ea8b9a229882e82e08287bb68a28fd4ecd2f.tar.gz
improved timeout example, fixes #1264
-rw-r--r--lib/timeout.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/timeout.js b/lib/timeout.js
index 7caba44..93fe2e1 100644
--- a/lib/timeout.js
+++ b/lib/timeout.js
@@ -16,12 +16,31 @@ import initialParams from './internal/initialParams';
* @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
* to timeout Error for more information..
* @returns {Function} Returns a wrapped function that can be used with any of
- * the control flow functions.
+ * the control flow functions. Invoke this function with the same
+ * parameters as you would `asyncFunc`.
* @example
*
- * async.timeout(function(callback) {
- * doAsyncTask(callback);
- * }, 1000);
+ * function myFunction(foo, callback) {
+ * doAsyncTask(foo, function(err, data) {
+ * // handle errors
+ * if (err) return callback(err);
+ *
+ * // do some stuff ...
+ *
+ * // return processed data
+ * return callback(null, data);
+ * });
+ * }
+ *
+ * var wrapped = async.timeout(myFunction, 1000);
+ *
+ * // call `wrapped` as you would `myFunction`
+ * wrapped({ bar: 'bar' }, function(err, data) {
+ * // if `myFunction` takes < 1000 ms to execute, `err`
+ * // and `data` will have their expected values
+ *
+ * // else `err` will be an Error with the code 'ETIMEDOUT'
+ * });
*/
export default function timeout(asyncFn, milliseconds, info) {
var originalCallback, timer;