According to documentation: Apple Developer Documentation
Don’t use a detached task if it’s possible to model the operation using structured concurrency features like child tasks. Child tasks inherit the parent task’s priority and task-local storage, and canceling a parent task automatically cancels all of its child tasks. You need to handle these considerations manually with a detached task.
You need to keep a reference to the detached task if you want to cancel it by calling the
Task.cancel() method. Discarding your reference to a detached task doesn’t implicitly cancel that task, it only makes it impossible for you to explicitly cancel the task.
But on the other hand, I actually wanna run a task in a new context away from
MainActor so I guess it makes sense. Does it mean that whenever we are trying to run background operation from main thread, we need to use
Task.detached and be sure it is being called from
MainActor as otherwise it would break the whole context and cancellation propagation?