Defines a common set of properties and methods that are shared with all dispatch source types.


protocol DispatchSourceProtocol


You do not adopt this protocol in your objects. Instead, use the makeSignalSource(signal:queue:) method to create an object that adopts this protocol.


Activating, Suspending, and Resuming a Source

func activate()

Activates the dispatch source.

func suspend()

Suspends the dispatch source.

func resume()

Resumes the dispatch source.

Canceling a Dispatch Source

func cancel()

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

var isCancelled: Bool

Returns a Boolean indicating whether the given dispatch source has been canceled.

func setCancelHandler(handler: DispatchWorkItem)

Sets the cancellation handler block for the dispatch source.

func setCancelHandler(qos: DispatchQoS, flags: DispatchWorkItemFlags, handler: Self.DispatchSourceHandler?)

Sets the cancellation handler block for the dispatch source with the specified quality-of-service class and work item options.

Getting the Dispatch Source Attributes

var handle: UInt

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

var data: UInt

Returns pending data for the dispatch source.

var mask: UInt

Returns the mask of events monitored by the dispatch source.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software