cancel

open fun cancel(cause: Throwable?): Boolean (source)

Overrides Job.cancel

Cancels this job with an optional cancellation cause. The result is true if this job was cancelled as a result of this invocation and false otherwise (if it was already completed or if it is NonCancellable). Repeated invocations of this function have no effect and always produce false.

When cancellation has a clear reason in the code, an instance of CancellationException should be created at the corresponding original cancellation site and passed into this method to aid in debugging by providing both the context of cancellation and text description of the reason.