Stop a Task and Async Task
Learn to stop a task and modify our notify_all function with Task.async.
We'll cover the following...
Stop a task
What happens if our task is stuck and never finishes?
While await/1
stops the task, yield/1
will leave it running. It is good to stop the task manually by calling Task.shutdown(task)
. The shutdown/1
function also accepts a timeout and gives the process the last chance to complete before stopping it. If it ends, we will receive the result as expected. We can also stop a process immediately by using the :brutal_kill
atom as the second argument.
As we can see, ...