News for hackers. Stuff that matters.
Re:A summary of ECMAScript 6 features by rzimmerman on Sunday February 15, 2015 @03:07AM (#9052062)
Generators in Python are a very useful feature (lazy sequences, like you said), so maybe I spoke to soon. However, I don't think people should be lauding this feature as some kind of solution to callback hell.

I just feel like priority-wise, users would benefit most from modules (which made it), async/await, maybe class syntactic sugar, then everything else.

Re:A summary of ECMAScript 6 features by RobertKerans on Sunday February 15, 2015 @06:19AM (#9052345)
FWIW, most of the stuff I've read on using generators to wrangle async has stressed that that's not the aim of the protocol, it's just a useful side-effect. But I think you are right, which is a bit of a shame really, given how useful generators can be - most every detailed article quickly skips through pretend toy examples, then <drumroll>aaaand async
Re:A summary of ECMAScript 6 features by masklinn on Sunday February 15, 2015 @03:41AM (#9052092)
> I don't think people should be lauding this feature as some kind of solution to callback hell.

Then async/await is no solution for it either.

Re:A summary of ECMAScript 6 features by rzimmerman on Sunday February 15, 2015 @05:35AM (#9052282)
I think:

    app.get('/thing', function (req, res) {
      try {
        await user = db.get({user: req.user});
        res.send({user:user});
      } catch {
        res.send(400);
      }
    });
beats the hell out of:

    app.get('/thing', function (req, res) {
      db.get({user: req.user}, function (err, user) {
        if (err) return res.send(400);
        res.send({user:user});
      });
    });
especially when you have conditionals or loops that can look like:

    if (user.name == 'abc') {
      resp = 5;
    } else {
      await resp = db.get_resp({user:user});
    }
    await db.save(something);
I suppose it doesn't get rid of callbacks, just makes them readable.
Re:A summary of ECMAScript 6 features by masklinn on Sunday February 15, 2015 @12:51PM (#9053329)
> I suppose it doesn't get rid of callbacks, just makes them readable.

You are the one who stated generators were no solution to callback hell but async/await was, yet here's what your code looks like with generators:

    app.get('/thing', function* (req, res) {
        try {
            let user = yield* db.get({user: req.user});
            res.send({user: user});
        } catch {
            res.send(400);
        }
    });
...
Re:A summary of ECMAScript 6 features by nawitus on Sunday February 15, 2015 @08:19AM (#9052524)
And the promise version for comparison:

    app.get('/thing', function (req, res) {
      db.get({user: req.user}).done(user => {
        res.send({user:user});
      }, error => {
        res.send(400);
      });
    });