Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/v3/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -14603,6 +14603,9 @@ <h4 class="name" id="series"><span class="type-signature">(static) </span>series
error to its callback, no more functions are run, and <code>callback</code> is
immediately called with the value of the error. Otherwise, <code>callback</code>
receives an array of results when <code>tasks</code> have completed.</p>
<p><strong>Note:</strong> Calling a task&apos;s callback with <code>false</code> cancels the series. The
remaining tasks and final <code>callback</code> will not run. Use <code>null</code> as the error
argument to continue after a successful task.</p>
<p>It is also possible to use an object instead of an array. Each property will
be run as a function, and the results will be passed to the final <code>callback</code>
as an object instead of an array. This can be a more readable way of handling
Expand Down
4 changes: 2 additions & 2 deletions docs/v3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ <h3>Binding a context to an iteratee</h3>
// will be as expected.
});
</code></pre>
<h3>Subtle Memory Leaks</h3>
<h3>Canceling an async flow</h3>
<p>There are cases where you might want to exit early from async flow, when calling an Async method inside another async function:</p>
<pre class="prettyprint source lang-javascript"><code>function myFunction (args, outerCallback) {
async.waterfall([
Expand All @@ -240,7 +240,7 @@ <h3>Subtle Memory Leaks</h3>
}
</code></pre>
<p>Something happened in a waterfall where you want to skip the rest of the execution, so you call an outer callack. However, Async will still wait for that inner <code>next</code> callback to be called, leaving some closure scope allocated.</p>
<p>As of version 3.0, you can call any Async callback with <code>false</code> as the <code>error</code> argument, and the rest of the execution of the Async method will be stopped or ignored.</p>
<p>As of version 3.0, calling any Async callback with <code>false</code> as the <code>error</code> argument cancels the flow: remaining work will be stopped or ignored, and the final callback will not run. Use <code>null</code> instead when a task succeeds and the flow should continue.</p>
<pre class="prettyprint source lang-javascript"><code> function (arg, next) {
if (someImportantCondition()) {
outerCallback(null)
Expand Down
3 changes: 3 additions & 0 deletions docs/v3/module-ControlFlow.html
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,9 @@ <h4 class="name" id="series"><span class="type-signature">(static) </span>series
error to its callback, no more functions are run, and <code>callback</code> is
immediately called with the value of the error. Otherwise, <code>callback</code>
receives an array of results when <code>tasks</code> have completed.</p>
<p><strong>Note:</strong> Calling a task&apos;s callback with <code>false</code> cancels the series. The
remaining tasks and final <code>callback</code> will not run. Use <code>null</code> as the error
argument to continue after a successful task.</p>
<p>It is also possible to use an object instead of an array. Each property will
be run as a function, and the results will be passed to the final <code>callback</code>
as an object instead of an array. This can be a more readable way of handling
Expand Down
4 changes: 4 additions & 0 deletions docs/v3/series.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ <h1 class="page-title">series.js</h1>
* immediately called with the value of the error. Otherwise, `callback`
* receives an array of results when `tasks` have completed.
*
* **Note:** Calling a task&apos;s callback with `false` cancels the series. The
* remaining tasks and final `callback` will not run. Use `null` as the error
* argument to continue after a successful task.
*
* It is also possible to use an object instead of an array. Each property will
* be run as a function, and the results will be passed to the final `callback`
* as an object instead of an array. This can be a more readable way of handling
Expand Down
4 changes: 2 additions & 2 deletions intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), fun
});
```

### Subtle Memory Leaks
### Canceling an async flow

There are cases where you might want to exit early from async flow, when calling an Async method inside another async function:

Expand All @@ -196,7 +196,7 @@ function myFunction (args, outerCallback) {

Something happened in a waterfall where you want to skip the rest of the execution, so you call an outer callack. However, Async will still wait for that inner `next` callback to be called, leaving some closure scope allocated.

As of version 3.0, you can call any Async callback with `false` as the `error` argument, and the rest of the execution of the Async method will be stopped or ignored.
As of version 3.0, calling any Async callback with `false` as the `error` argument cancels the flow: remaining work will be stopped or ignored, and the final callback will not run. Use `null` instead when a task succeeds and the flow should continue.

```javascript
function (arg, next) {
Expand Down
4 changes: 4 additions & 0 deletions lib/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import eachOfSeries from './eachOfSeries.js'
* immediately called with the value of the error. Otherwise, `callback`
* receives an array of results when `tasks` have completed.
*
* **Note:** Calling a task's callback with `false` cancels the series. The
* remaining tasks and final `callback` will not run. Use `null` as the error
* argument to continue after a successful task.
*
* It is also possible to use an object instead of an array. Each property will
* be run as a function, and the results will be passed to the final `callback`
* as an object instead of an array. This can be a more readable way of handling
Expand Down