Your "if" needs an else clause to ensure the callback is eventually invoked.
On Sun, Sep 21, 2014 at 8:08 PM, Matt <[email protected]> wrote: > > On Sat, Sep 20, 2014 at 9:17 AM, Bruno Jouhier <[email protected]> wrote: >> >> How do you implement it with async? > > > This is a good question, so here's an example translation (not the only way > to do it): > > > CDN.use(config.CDN.baseUrl, function(req, res, next) { > if(err) return next(err); > async.waterfall([ > function (cb) { > fs.lstat(config.base+"/cdn"+req.url, cb); > }, > function (stats, cb) { > if(stats.isSymbolicLink()) { > async.waterfall([ > function (cb) { > fs.readlink(config.base+"/cdn"+req.url, cb); > }, > function (linkstr, cb) { > log.info("Redirecting request \""+req.url+"\" to > \""+linkstr); > fs.readFile(linkstr, cb); > }, > ], cb); > } > } > ], function (err, data) { > if (err) return next(err); > res.writeHead(200,{"Content-type":"text/html"}); > res.end(data); > }); > }); > > It's more code, but it improves the error checking. If it didn't have that > "if" statement in there it would be a lot simpler - async code doesn't deal > well with "if" statements I've found (there's no way to short-circuit). > > Matt. > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to a topic in the > Google Groups "nodejs" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/nodejs/wBAJhYOzjqQ/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/CAPJ5V2Z8yeYWX_HXaJqvbid5K%2B1T%3DNz--VF0GtXnKr%2BsyZsQrA%40mail.gmail.com. > > For more options, visit https://groups.google.com/d/optout. -- THOMAS BOUTELL, DEV & OPS P'UNK AVENUE | (215) 755-1330 | punkave.com -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAORXhG%2B5kdGAuewcm_fhzqubxfHz7n2X_-va99z_e-7amc6Cug%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
