diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2016-11-24 23:17:27 -0500 |
---|---|---|
committer | Hubert Argasinski <argasinski.hubert@gmail.com> | 2016-11-24 23:17:27 -0500 |
commit | 8ac2fd0c28670f5fafe4c6ba822e1d379f277df9 (patch) | |
tree | 1d9648c10345a4aef865b19609610ac7b0742728 | |
parent | 7a6a50040db4997db3e8bf8726338a86e759e949 (diff) | |
download | async-8ac2fd0c28670f5fafe4c6ba822e1d379f277df9.tar.gz |
docs: make style consistent for intro examples
-rw-r--r-- | intro.md | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -28,7 +28,7 @@ callback as the last argument of your asynchronous function -- a callback which ## Quick Examples ```js -async.map(['file1','file2','file3'], fs.stat, function(err, results){ +async.map(['file1','file2','file3'], fs.stat, function(err, results) { // results is now an array of stats for each file }); @@ -36,20 +36,20 @@ async.filter(['file1','file2','file3'], function(filePath, callback) { fs.access(filePath, function(err) { callback(null, !err) }); -}, function(err, results){ +}, function(err, results) { // results now equals an array of the existing files }); async.parallel([ - function(callback){ ... }, - function(callback){ ... } + function(callback) { ... }, + function(callback) { ... } ], function(err, results) { // optional callback }); async.series([ - function(callback){ ... }, - function(callback){ ... } + function(callback) { ... }, + function(callback) { ... } ]); ``` @@ -82,7 +82,7 @@ Just change it to: ```js async.eachSeries(hugeArray, function iteratee(item, callback) { if (inCache(item)) { - async.setImmediate(function () { + async.setImmediate(function() { callback(null, cache[item]); }); } else { @@ -103,7 +103,7 @@ Make sure to always `return` when calling a callback early, otherwise you will c ```js async.waterfall([ - function (callback) { + function(callback) { getSomething(options, function (err, result) { if (err) { callback(new Error("failed getting something:" + err.message)); @@ -139,14 +139,14 @@ var AsyncSquaringLibrary = { } }; -async.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result){ +async.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result) { // result is [NaN, NaN, NaN] // This fails because the `this.squareExponent` expression in the square // function is not evaluated in the context of AsyncSquaringLibrary, and is // therefore undefined. }); -async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result){ +async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result) { // result is [1, 4, 9] // With the help of bind we can attach a context to the iteratee before // passing it to async. Now the square function will be executed in its @@ -196,7 +196,7 @@ Usage: <script type="text/javascript" src="async.js"></script> <script type="text/javascript"> - async.map(data, asyncProcess, function(err, results){ + async.map(data, asyncProcess, function(err, results) { alert(results); }); @@ -215,4 +215,3 @@ $ npm install --save async-es import waterfall from 'async-es/waterfall'; import async from 'async-es'; ``` - |