Cancellable-coroutine is a wrapper for function generators that runs them as async functions and adds cancellation support.
// Take a generator function;// Wrap the generator in Cancellable.create(...);// Run the wrapped function, which runs like a function using `async/await`.// The function returns a promise, which resolves on complete, or rejects on uncaught exception or cancellation.cancellableFn''.thenonComplete, onFailureOrCancel;// Now we can halt the execution of our generator function whenever we want! We use Cancellable.cancel(..) to cancel.setTimeout, 200;
When calling this
generatorFn will run like an
async/await function (all
yield expressions will resolve in sequence).
cancellableTask is running, a
CancelError will be thrown in the wrapped generator function. If the task is not running, nothing will happen.
Extends Error. A CancelError will be thrown into the generator function if it is cancelled while running.
Returns true if the passed error is a CancelError, false otherwise. This can be used in a
catch(error) block to check whether
error was caused by cancellation or not.
Returns true if the passed task has been cancelled. This can be used in a calling function to check whether a called task ran successfully or was cancelled.