co-nothrow
0.0.1 • Public • Published co-nothrow
A no-throw style of co.js, better for explicit error handling like that in Go and Lua.
Usage and Comparison
Originally with co.js
const co = require("co");
co(function *() {
try {
let res = yield doSomethingAsync();
}catch(e){
return reportError(e);
}
});
Now with co-nothrow
const co = require("co-nothrow");
co(function *() {
let ret = yield doSomethingAsync();
if(ret[0]){
return reportError(ret[0])
}
});
For Node.js v6+, with ES6 destructing
.
const co = require("co-nothrow");
co(function *() {
let [err, res] = yield doSomethingAsync();
if(err){
return reportError(res)
}
});
License
MIT
Package Sidebar
Install
Weekly Downloads