<!--
{
  "documentType" : "article",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/dispatch-source",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Dispatch Source"
}
-->

# Dispatch Source

An object that coordinates the processing of specific low-level system events, such as file-system events, timers, and UNIX signals.

## Topics

### Creating a Dispatch Source

[`extern dispatch_source_tdispatch_source_create(dispatch_source_type_t type, uintptr_t handle, uintptr_t mask, dispatch_queue_t queue);`](/documentation/Dispatch/dispatch_source_create)

Creates a new dispatch source to monitor low-level system events.

[`typealias dispatch_source_t`](/documentation/Dispatch/dispatch_source_t)

An object that coordinates the processing of specific low-level system events, such as file-system events, timers, and UNIX signals.

[`typedef const struct dispatch_source_type_s * dispatch_source_type_t;`](/documentation/Dispatch/dispatch_source_type_t)

An identifier for the type of system object being monitored by a dispatch source.

### Managing Event Handlers

[`extern void dispatch_source_set_registration_handler_f(dispatch_source_t source, dispatch_function_t handler);`](/documentation/Dispatch/dispatch_source_set_registration_handler_f)

Sets the registration handler function for the given dispatch source.

[`extern void dispatch_source_set_registration_handler(dispatch_source_t source, dispatch_block_t handler);`](/documentation/Dispatch/dispatch_source_set_registration_handler)

Sets the registration handler block for the given dispatch source.

[`extern void dispatch_source_set_event_handler_f(dispatch_source_t source, dispatch_function_t handler);`](/documentation/Dispatch/dispatch_source_set_event_handler_f)

Sets the event handler function for the given dispatch source.

[`extern void dispatch_source_set_event_handler(dispatch_source_t source, dispatch_block_t handler);`](/documentation/Dispatch/dispatch_source_set_event_handler)

Sets the event handler block for the given dispatch source.

[`extern void dispatch_source_set_cancel_handler_f(dispatch_source_t source, dispatch_function_t handler);`](/documentation/Dispatch/dispatch_source_set_cancel_handler_f)

Sets the cancellation handler function for the given dispatch source.

[`extern void dispatch_source_set_cancel_handler(dispatch_source_t source, dispatch_block_t handler);`](/documentation/Dispatch/dispatch_source_set_cancel_handler)

Sets the cancellation handler block for the given dispatch source.

### Getting Dispatch Source Attributes

[`extern uintptr_t dispatch_source_get_data(dispatch_source_t source);`](/documentation/Dispatch/dispatch_source_get_data)

Returns pending data for the dispatch source.

[`extern uintptr_t dispatch_source_get_mask(dispatch_source_t source);`](/documentation/Dispatch/dispatch_source_get_mask)

Returns the mask of events monitored by the dispatch source.

[`extern uintptr_t dispatch_source_get_handle(dispatch_source_t source);`](/documentation/Dispatch/dispatch_source_get_handle)

Returns the underlying system handle associated with the specified dispatch source.

[`extern void dispatch_source_merge_data(dispatch_source_t source, uintptr_t value);`](/documentation/Dispatch/dispatch_source_merge_data)

Merges data into a dispatch source and submits its event handler block to its target queue.

[`typedef unsigned long dispatch_source_proc_flags_t;`](/documentation/Dispatch/dispatch_source_proc_flags_t)

Events related to a process.

[`typedef unsigned long dispatch_source_vnode_flags_t;`](/documentation/Dispatch/dispatch_source_vnode_flags_t)

Events involving a change to a file system object.

[`typealias dispatch_source_mach_recv_flags_t`](/documentation/Dispatch/dispatch_source_mach_recv_flags_t)

Mach receive-right flags.

[`typedef unsigned long dispatch_source_mach_send_flags_t;`](/documentation/Dispatch/dispatch_source_mach_send_flags_t)

Mach send-right flags.

[`typedef unsigned long dispatch_source_memorypressure_flags_t;`](/documentation/Dispatch/dispatch_source_memorypressure_flags_t)

Memory pressure events.

### Managing Timer Parameters

[`extern void dispatch_source_set_timer(dispatch_source_t source, dispatch_time_t start, uint64_t interval, uint64_t leeway);`](/documentation/Dispatch/dispatch_source_set_timer)

Sets a start time, interval, and leeway value for a timer source.

[`typedef unsigned long dispatch_source_timer_flags_t;`](/documentation/Dispatch/dispatch_source_timer_flags_t)

Flags to use when configuring a timer dispatch source.

### Canceling a Dispatch Source

[`extern void dispatch_source_cancel(dispatch_source_t source);`](/documentation/Dispatch/dispatch_source_cancel)

Asynchronously cancels the dispatch source, preventing any further invocation of its event handler block.

[`extern intptr_t dispatch_source_testcancel(dispatch_source_t source);`](/documentation/Dispatch/dispatch_source_testcancel)

Tests whether the given dispatch source has been canceled.



---

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)