<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Task/init(name:priority:operation:)-43wmk",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScT12_Concurrencys5Error_pRs_rlE4name8priority9operationScTyxsAB_pGSSSg_ScPSgxyYaKYAcntcfc"
  },
  "title" : "init(name:priority:operation:)"
}
-->

# init(name:priority:operation:)

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

```
@discardableResult init(name: String? = nil, priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async throws -> Success)
```

## Parameters

`name`

Human readable name of the task.

`priority`

The priority of the operation task.

`operation`

The operation to perform.

## Return Value

A reference to the task.

## Discussion

If the `operation` throws an error, it is caught by the `Task` and will be
rethrown only when the task’s `value` is awaited. Take care to not accidentally
dismiss errors by not awaiting on the task’s resulting value.

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)