diff --git a/lib/koroutine.js b/lib/koroutine.js index a97dad4..24c99db 100644 --- a/lib/koroutine.js +++ b/lib/koroutine.js @@ -141,6 +141,7 @@ function run(generator, timeout, ...rest) { timer = null; } debug("Coroutine threw error: %s", e); + throw e; } finally { current.context = null; diff --git a/test/koroutine.test.js b/test/koroutine.test.js index 7e53eb2..fd470d8 100644 --- a/test/koroutine.test.js +++ b/test/koroutine.test.js @@ -30,7 +30,7 @@ function* testSequentialCalls(test) { test.deepEqual(result, ['input-2', 'arg-1', 'arg-2']); try { - yield* sequentialCallError(this, "error-1", 150); + yield* sequentialCallError(this, "error-1", 150); } catch (e) { test.equal(e.message, "error-1"); test.equal(e.cause, "exception"); @@ -211,7 +211,11 @@ exports['Test koroutine current context'] = function(test) { function * testExceptionThrower(test) { throw new Error("Uncaught Exception!"); } + exports['Test coroutine throwing uncaught exception'] = function(test) { - koroutine.run(testExceptionThrower, 1000, test); - test.done(); + try { + koroutine.run(testExceptionThrower, 1000, test); + } catch (e) { + test.done(); + } }