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

    deadline

    The timespan to delay a closure execution

    context

    The context in which the throttle should be executed

    action

    The closure to be executed