Canceling a Coroutine

Learn how to stop a thread by canceling a coroutine.

We'll cover the following...

If you’re a Java developer, you may already know that stopping a thread is quite complicated.

For example, the Thread.stop() method is deprecated. There’s Thread.interrupt(), but not all threads are checking this flag, not to mention setting a volatile flag, which is often suggested but is very cumbersome.

If we are using a thread pool, we will get Future, which has the cancel(boolean mayInterruptIfRunning) method. In ...