DispatchQueue
Adds throttling to dispatch queues
-
Stores a throttle DispatchWorkItem instance for a given context
Declaration
Swift
private static var workItems = [AnyHashable: DispatchWorkItem]() -
An object representing a context if none is given
Declaration
Swift
private static let nilContext = UUID() -
Delays a closure execution and ensures no other executions are made during deadline for that context
Declaration
Swift
func throttle(deadline: DispatchTime, context: AnyHashable = nilContext, action: @escaping () -> Void)Parameters
deadlineThe timespan to delay a closure execution
contextThe context in which the throttle should be executed
actionThe closure to be executed
DispatchQueue Extension Reference