> I think you just reinvented node.js core function named `domain.intercept`. :)
Domains are still experimental (and doesn't have support in browser). Also, I believe that if you decide to use the dark side of the Force - it's better to use it at the full potential with the Fibers. > Reads much nicer even if it is more lines of code. Nicer? :) Don't know, for me the nice version is the synchronous one (with generators, code generators, yields, fibers etc.), but I believe the version with fork is still shorter and simpler. On Tuesday, 16 September 2014 04:38:53 UTC+4, Alex Kocharin wrote: > > > I think you just reinvented node.js core function named > `domain.intercept`. :) > > > 16.09.2014, 01:34, "Alexey Petrushin" <alexey.p...@gmail.com <javascript:> > >: > > I wrote short article > http://jslang.info/blog/2014/escape-from-callback-hell > > about simple approach that turn this > > var printCommentsForUser = function(login, password, cb){ > authenticateUser(login, password, function(err, user){ > if(err) return cb(err) > getComments(user.id, function(err, comments){ > if(err) return cb(err) > renderComments(user, comments, cb) > }) > }) > } > > Into this > > var printCommentsForUserWithFork = function(login, password, ecb, cb){ > authenticateUser(login, password, ecb, function(user){ > getComments(user.id, ecb, function(comments){ > renderComments(user, comments, ecb, cb) > }) > }) > } > > Or this > > var printCommentsForUserWithTwoCallbacks = function(login, password, > ecb, cb){ > authenticateUser(login, password, ecb, function(user){ > getComments(user.id, ecb, function(comments){ > renderComments(user, comments, ecb, cb) > }) > }) > } > > On Monday, 15 September 2014 20:28:28 UTC+4, Ingwie Phoenix wrote: > > Hai, everyone. > > So I just figured out that Connect’s static file servers dont work well > with symlinks…so I had tow rite myself a little workaround, a fallback > router, per-se. But whilst I did so, I had a nice meeting with the callback > hell. Here’s my code: > > CDN.use(config.CDN.baseUrl, function(req, res, next){ > if(err) { next(); throw err; } > fs.lstat(config.base+"/cdn"+req.url, function(err,stats){ > if(stats.isSymbolicLink()) { > fs.readlink(config.base+"/cdn"+req.url, > function(err, linkstr){ > if(err) throw err; > log.info("Redirecting request \""+req.url+"\" > to \""+linkstr); > fs.readFile(linkstr, function(err, data){ > if(err) throw err; > > res.writeHead(200,{"Content-type":"text/html"}); > res.end(data); > }); > }); > } > }); > }); > }); > > Okay…thats lots. And how does one get around this and into a bit of nicer > code? It almost looks like a little pyramid there… > > Kind regards, Ingwie. > > > -- > 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 nodejs+un...@googlegroups.com <javascript:>. > To post to this group, send email to nod...@googlegroups.com <javascript:> > . > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/32603590-e433-43a9-860a-8c12fdbac3f9%40googlegroups.com > > <https://groups.google.com/d/msgid/nodejs/32603590-e433-43a9-860a-8c12fdbac3f9%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- 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 nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/30d59dad-1844-41a2-b3e7-910941667055%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.