---
title: "detached(name:priority:operation:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/task/detached(name:priority:operation:)-9xki7"
---

# detached(name:priority:operation:)

Runs the given nonthrowing operation asynchronously as part of a new unstructured detached top-level task.

## Declaration

```swift
@discardableResult static func detached(name: String? = nil, priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async -> Success) -> Task<Success, Never>
```

## Parameters

- `name`: Human readable name of the task.
- `priority`: The priority of the operation task. Omit this parameter or pass nil to inherit the enclosing context’s base priority.
- `operation`: The operation to perform.

## Return Value

Return Value A reference to the task.

## Discussion

Discussion Don’t use a detached unstructured 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 task if you want to cancel it by calling the Task.cancel() method. Discarding your reference to a task doesn’t implicitly cancel that task, it only makes it impossible for you to explicitly cancel the task.

## See Also

### Creating a Detached Task

- [detached(name:priority:operation:)](swift/task/detached(name:priority:operation:)-795w1.md)
- [detached(name:executorPreference:priority:operation:)](swift/task/detached(name:executorpreference:priority:operation:)-6r16s.md)
- [detached(name:executorPreference:priority:operation:)](swift/task/detached(name:executorpreference:priority:operation:)-75ffe.md)
