4 ms·
Using abstractions like http://koajs.com/ http://koajs.com/ and https://github.com/tj/co https://github.com/tj/co make Node code feel like every other language.
by danneu 11y ago
Using abstractions like http://koajs.com/ http://koajs.com/ and https://github.com/tj/co https://github.com/tj/co make Node code feel like every other language.
var user;
try {
user = yield db.insertUser('foo')
} catch(err) {
if (err.code === '23505') {
this.flash['error'] = 'Username taken';
this.redirect('/register');
return;
}
throw err;
}
- aikah 11y agono because you can't write a library which apis are thunks. And your code needs to run in a generator, something you omitted. Fibers are a better alternative , no need for yield and generators everywhere.
- danneu 11y agoWell, I was earnestly sharing run-of-the-mill Koa code since you made async abstractions sound elusive. Didn't realize you just had an agenda. The thing is that people are actually using Koa/co to solve this problem. I've yet to see someone use fibers as their core webapp control flow abstraction.
- aikah 11y agoWhat agenda do I have ? I have none, I'm just saying using generators do not abstract async calls. The only way to do that is by using fibers. I'm not pushing for anything, i'm just saying that something like rails couldn't be written in nodejs , (and no sails , is nothing like rails in terms of complexity ).
- danneu 11y agoIt's your fiber agenda. My mother used it to try to make me eat my brussels sprouts and I thwarted that, too.