Cancelling Coroutines in Kotlin
Too Long; Didn't Read
Coroutines provide a simple undo mechanism to solve problems with long-running operations or memory leaks. The cancellation of a coroutine is fully thread-safe and non-blocking. We can use cancellation in coroutines for easy resource cleaning or possibly some form of error logging. If the job is canceled, a ‘CancellationException` will be thrown. We can also combine these two calls into the ‘job.cancelAndJoin()` function. If we need to wait for the Job to be complete, we can use the `job.join().