News for hackers. Stuff that matters.
Re:Node v4.0.0 by aikah on Tuesday September 08, 2015 @04:51PM (#10188152)
> I don't think most people working on Node want a Rails equivalent

It wouldn't really be possible anyway. Async programming is hard and the shortcuts one can take with synchronous Ruby are impossible with Async Javascript. Nodejs has a "fibers" lib though , but it doesn't look like it is widely popular, but AFAIK it is the only to truly abstract async programming.

Re:Node v4.0.0 by ivank on Tuesday September 08, 2015 @07:39PM (#10188831)
Try bluebird's Promise.coroutine, I use it everywhere and it works great.

https://github.com/petkaantonov/bluebird/blob/master/API.md#...

Re:Node v4.0.0 by Dashron on Tuesday September 08, 2015 @11:11PM (#10189457)
Or if you want to use native promises, I threw this together

https://github.com/Dashron/roads-coroutine

Re:Node v4.0.0 by girvo on Tuesday September 08, 2015 @07:38PM (#10188827)
ECMAScript 7 has brought true async/await into the language, which currently works in Babel on top of Promises. As far as a regular user is concerned, define a function as "async" and then "await" on the result you're after inside of it. Hardly difficult, in my opinion!
Re:Node v4.0.0 by spankalee on Tuesday September 08, 2015 @08:09PM (#10188922)
async/await is nice syntax, but it doesn't change the fundamental difference between synchronous and asynchronous code and the viral nature of async functions. Sync functions cannot properly compose async functions in general.

A great essay on this is "What Color is Your Function": http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...

Re:Node v4.0.0 by danneu on Tuesday September 08, 2015 @06:56PM (#10188672)
Using abstractions like http://koajs.com/ and 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;
    }
Re:Node v4.0.0 by aikah on Tuesday September 08, 2015 @10:06PM (#10189274)
no 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.
Re:Node v4.0.0 by danneu on Wednesday September 09, 2015 @12:25PM (#10192356)
Well, 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.

Re:Node v4.0.0 by aikah on Wednesday September 09, 2015 @12:54PM (#10192552)
What 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 ).
Re:Node v4.0.0 by danneu on Wednesday September 09, 2015 @09:54PM (#10195787)
It's your fiber agenda. My mother used it to try to make me eat my brussels sprouts and I thwarted that, too.
Re:Node v4.0.0 by TheAceOfHearts on Wednesday September 09, 2015 @06:42AM (#10190680)
With async functions you interface with everything using promises, it's great.