This looks correct to me.
It's also worth noting that detached Tasks have a bunch of other effects besides changing context inheritance, including not sharing Task-local variables with the parent, and not inheriting priority in the same way.
Because of this I'm always pretty skeptical of using detached
just to disable inheritance; I would generally prefer moving the code to an @concurrent async
function and calling that from the Task
(or eliminating the Task entirely if the caller is also async).
If you're familiar with DispatchQueue
, the equivalent concept is DISPATCH_BLOCK_DETACHED | Apple Developer Documentation