diff options
author | Beau Gunderson <beau@beaugunderson.com> | 2014-10-13 10:53:26 -0700 |
---|---|---|
committer | Beau Gunderson <beau@beaugunderson.com> | 2014-10-13 10:53:28 -0700 |
commit | 2a9145a93fe783ab62502b8be761d1c89651a4e4 (patch) | |
tree | f025f2647f3765ec36ed86426f5fed1fe697c78b | |
parent | 232121251f601c9be7209f6382ee32180df676f1 (diff) | |
download | async-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.md | 23 |
1 files changed, 8 insertions, 15 deletions
@@ -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); - } + }); +} }); ``` |