summaryrefslogtreecommitdiff
path: root/lib/forever.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/forever.js')
-rw-r--r--lib/forever.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/forever.js b/lib/forever.js
index fb69adf..4914c21 100644
--- a/lib/forever.js
+++ b/lib/forever.js
@@ -1,7 +1,7 @@
-import noop from './internal/noop';
import onlyOnce from './internal/onlyOnce';
import ensureAsync from './ensureAsync';
import wrapAsync from './internal/wrapAsync';
+import awaitify from './internal/awaitify'
/**
* Calls the asynchronous function `fn` with a callback parameter that allows it
@@ -19,6 +19,8 @@ import wrapAsync from './internal/wrapAsync';
* Invoked with (next).
* @param {Function} [errback] - when `fn` passes an error to it's callback,
* this function will be called, and execution stops. Invoked with (err).
+ * @returns {Promise} a promise that rejects if an error occurs and an errback
+ * is not passed
* @example
*
* async.forever(
@@ -32,8 +34,8 @@ import wrapAsync from './internal/wrapAsync';
* }
* );
*/
-export default function forever(fn, errback) {
- var done = onlyOnce(errback || noop);
+function forever(fn, errback) {
+ var done = onlyOnce(errback);
var task = wrapAsync(ensureAsync(fn));
function next(err) {
@@ -41,5 +43,6 @@ export default function forever(fn, errback) {
if (err === false) return;
task(next);
}
- next();
+ return next();
}
+export default awaitify(forever, 2)