summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alex@npmjs.com>2018-06-10 18:56:07 -0700
committerAlexander Early <alex@npmjs.com>2018-06-10 18:56:07 -0700
commit93591bf173082d01fdc8dbbb55039bc49befec70 (patch)
tree79688e8f8d65fc370003423e0273cd158d0b815e
parentcccd88961138247a15d026ae51d36705aed3a6d2 (diff)
downloadasync-canceling.tar.gz
-rw-r--r--intro.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/intro.md b/intro.md
index 43d3c81..fe27c65 100644
--- a/intro.md
+++ b/intro.md
@@ -173,6 +173,40 @@ async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), fun
});
```
+### Subtle Memory Leaks
+
+There are cases where you might want to exit early from async flow, when calling an Async method insice another async function:
+
+```javascript
+function myFunction (args, outerCallback) {
+ async.waterfall([
+ //...
+ function (arg, next) {
+ if (someImportantCondition()) {
+ return outerCallback(null)
+ }
+ },
+ function (arg, next) {/*...*/}
+ ], function done (err) {
+ //...
+ })
+}
+```
+
+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.
+
+```javascript
+ function (arg, next) {
+ if (someImportantCondition()) {
+ outerCallback(null)
+ return next(false) // ← signal that you called an outer callback
+ }
+ },
+```
+
+
## Download
The source is available for download from