4 ms·
And here's how to do the same in plain JS with ES6, available now in node (--harmony) and (I believe?) Chrome Canary. function *() { try { le
by sync 12y ago
And here's how to do the same in plain JS with ES6, available now in node (--harmony) and (I believe?) Chrome Canary.
function *() {
try {
let body = yield request("https://x.io/");
return yield request("https://x.io/?q=" + body.hash);
} catch (e) {
// do what you like with the error
}
}
- jashkenas 12y agoAnd here's how to do the same in plain CoffeeScript with generators — using a new patch landed a couple of minutes ago: https://github.com/jashkenas/coffeescript/pull/3240/files https://github.com/jashkenas/coffeescript/pull/3240/files -> try body = yield request "https://x.io/" yield request "https://x.io/?q=#{body.hash}" catch e # do what you like with the error ... the salient bit being that there's no need to declare a generator function as a "special" type of function different from any other — a generator is simply a function that yields.
- jb55 12y agoNote that this is just a generator yielding callback functions/promises. You need an interpreter such as co to actually run them.