0.0.1 • Published 8 years ago

co-nothrow v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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);
	}
	//continue with result in res
});

Now with co-nothrow

const co = require("co-nothrow");
co(function *() {
	let ret = yield doSomethingAsync();
	if(ret[0]){
		return reportError(ret[0])
	}
	//continue with result in 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)
	}
	//continue with res
});

License

MIT