<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchQueue/asyncAndWait(execute:)-1udeu",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_async_and_wait"
  },
  "title" : "asyncAndWait(execute:)"
}
-->

# asyncAndWait(execute:)

Submits a work item for execution and returns only after it finishes executing.

```
func asyncAndWait(execute block: () -> Void)
```

## Parameters

`block`

The block that contains the work to perform. This block has no return value and no parameters. This parameter cannot be `NULL`.

## Discussion

This function submits work to the specified queue for execution. Unlike [`dispatch_async`](/documentation/Dispatch/dispatch_async), this function does not return until after the block finishes. Calling this function and targeting the current queue results in deadlock.

Unlike [`sync(execute:)`](/documentation/Dispatch/DispatchQueue/sync(execute:)-3segw), this function respects all attributes of the queue when it executes the block. For example, it respects the quality-of-service level and autorelease frequency of the target queue.

If the runtime has already brought up a thread to service asynchronous work items, the system uses that same thread to execute any synchronous blocks you submitted using this function. If the runtime hasn’t brought up a thread to service asynchronous work items, the sytem executes these synchronous blocks on the current thread as an optimization. However, these optimizations apply only when `queue` targets a global concurrent queue. If it targets any other queue, the system executes the work on that queue’s thread. For example, if `queue` targets the main queue, the block always runs on the main thread.

Unlike with [`dispatch_async`](/documentation/Dispatch/dispatch_async), no retain is performed on the target queue. Because calls to this function are synchronous, it “borrows” the reference of the caller. Moreover, no `Block_copy` is performed on the block.

---

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)