Dispatch Work Item

The work you want to perform, encapsulated in a way that lets you attach a completion handle or execution dependencies.

Overview

A dispatch work item encapsulates work to be performed on a dispatch queue or within a dispatch group. You can also use a work item as a dispatch source event, registration, or cancellation handler.

Topics

Creating a Work Item

dispatch_block_create

Creates a new dispatch block on the heap using an existing block and the given flags.

dispatch_block_create_with_qos_class

Creates a new dispatch block from an existing block and the given flags, and assigns it the specified quality-of-service class and relative priority.

dispatch_block_t

The prototype of blocks submitted to dispatch queues, which take no arguments and have no return value.

Scheduling Work Items

dispatch_block_perform

Creates, synchronously executes, and releases a dispatch block from the specified block and flags.

Adding a Completion Handler

dispatch_block_notify

Schedules a notification block to be submitted to a queue when the execution of a specified dispatch block has completed.

Delaying Execution of a Work Item

dispatch_block_wait

Waits synchronously until execution of the specified dispatch block has completed or until the specified timeout has elapsed.

Canceling a Work Item

dispatch_block_cancel

Cancels the specified dispatch block asynchronously.

dispatch_block_testcancel

Tests whether the given dispatch block has been canceled.

See Also

Queues and Tasks

dispatch_get_main_queue

Returns the serial dispatch queue associated with the application’s main thread.

dispatch_get_global_queue

Returns a system-defined global concurrent queue with the specified quality-of-service class.

Dispatch Queue

An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.

Dispatch Group

A group of tasks that you monitor as a single unit.