How to check for error when using yield instead of node-style callback?

Viewed 9840

I'm wrapping my head around the new ecma6 generators and yield-operator in javascript, specifically in the context of koa.

Consider the contrived example:

  newUser.save(function(err, user) {
    if(err){
      //do something with the error
    }
    console.log("user saved!: " user.id);
  }

'Yieldified' this would look something like this:

  var user = yield newUser.save();
  console.log("user saved!: " user.id);

But how would I check for err to exist, with the purpose of executing //do something with the error?

2 Answers
Related