diff options
author | kybernetikos <me@kybernetikos.com> | 2014-02-12 14:06:17 +0000 |
---|---|---|
committer | kybernetikos <me@kybernetikos.com> | 2014-02-12 14:06:17 +0000 |
commit | eea14ed194dff46540eee196400acdfc0c8b7480 (patch) | |
tree | c9c1607443f842af2d140fd7cbda6684309140da /README.md | |
parent | 2d5bc3f5a6db2d699646e59a551355a21cd98637 (diff) | |
download | async-eea14ed194dff46540eee196400acdfc0c8b7480.tar.gz |
Added a little more description to 'forever'
The forever section is unclear at present because there are two callback functions in play (the second argument in forever, and the first argument for fn), and also because it's not made clear that execution will stop if next is not called or if next is called with an argument.
This change is my suggestion to make it a little clearer.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -800,11 +800,26 @@ Like doWhilst except the test is inverted. Note the argument ordering differs fr --------------------------------------- <a name="forever" /> -### forever(fn, callback) +### forever(fn, errback) -Calls the asynchronous function 'fn' repeatedly, in series, indefinitely. -If an error is passed to fn's callback then 'callback' is called with the -error, otherwise it will never be called. +Calls the asynchronous function 'fn' with a callback parameter that allows it to +call itself again, in series, indefinitely. + +If an error is passed to the callback then 'errback' is called with the +error, and execution stops, otherwise it will never be called. + +```js +async.forever( + function(next) { + // next is suitable for passing to things that need a callback(err [, whatever]); + // it will result in this function being called again. + }, + function(err) { + // if next is called with a value in its first parameter, it will appear + // in here as 'err', and execution will stop. + } +); +``` --------------------------------------- |