co2 is an extended replacement for the lua (inbuilt) coroutine library.
It was conceived mostly because of my constant frustration that coroutine.resume
acts like pcall, and not a normal call.
The functionality provided by co2 differs from the coroutine library in a few significant ways:
co2.resume
propagates errors properly. When an error occurs in a coroutine,coroutine.resume
acts like pcall and returns it,co2.resume
instead throws a new error in the calling coroutine.co2.presume
implements thecoroutine.resume
semantics.co2.xpresume
is thexpcall
version ofco2.resume
. Callco2.xpresume
with a coroutine, a handler, and the arguments to resume the coroutine with. In case of an error, the handler is called with the error message, and the coroutine that errored.- It comes with an integrated traceback utility
co2.traceback
. This traceback combines both the traceback of the supplied coroutine, and the calling coroutine. Mostly useful when combined withco2.xpresume
.
The best way to obtain this library is via luarocks. Alternatively, you can use this library by placing the contents of the src directory in a location on your lua load path.
Once installed, you can require the co2 library as follows:
local co2 = require "co2"
You can run the provided unit tests using the busted test framework.
When installed you can run busted tests
from the root of this repository.