summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeau Gunderson <beau@beaugunderson.com>2014-10-13 10:53:26 -0700
committerBeau Gunderson <beau@beaugunderson.com>2014-10-13 10:53:28 -0700
commit2a9145a93fe783ab62502b8be761d1c89651a4e4 (patch)
treef025f2647f3765ec36ed86426f5fed1fe697c78b
parent232121251f601c9be7209f6382ee32180df676f1 (diff)
downloadasync-2a9145a93fe783ab62502b8be761d1c89651a4e4.tar.gz
Improve documentation for async.seq
- seq requires the last argument to be a function - seq short-circuits on errors which means using handleError is redundant
-rw-r--r--README.md23
1 files changed, 8 insertions, 15 deletions
diff --git a/README.md b/README.md
index 8f4e98c..49189b2 100644
--- a/README.md
+++ b/README.md
@@ -989,28 +989,21 @@ __Example__
// This example uses `seq` function to avoid overnesting and error
// handling clutter.
app.get('/cats', function(request, response) {
- function handleError(err, data, callback) {
- if (err) {
- console.error(err);
- response.json({ status: 'error', message: err.message });
- }
- else {
- callback(data);
- }
- }
var User = request.models.User;
async.seq(
_.bind(User.get, User), // 'User.get' has signature (id, callback(err, data))
- handleError,
function(user, fn) {
user.getCats(fn); // 'getCats' has signature (callback(err, data))
- },
- handleError,
- function(cats) {
+ }
+ )(req.session.user_id, function (err, cats) {
+ if (err) {
+ console.error(err);
+ response.json({ status: 'error', message: err.message });
+ } else {
response.json({ status: 'ok', message: 'Cats found', data: cats });
}
- )(req.session.user_id);
- }
+ });
+}
});
```