DefaultActionDispatcher

public class DefaultActionDispatcher : ActionDispatcher

The default dispatcher implementation that provides the ability to observe when actions are performed, across sessions.

This will attempt to detect if the caller is on the queue the action expects, and avoid crashing with a DispatchQueue.sync call when already on that queue. If the current queue is not the action’s queue, it will use a DispatchQueue.sync.

The goal is that if the app is on the main queue, call perform and the dispatcher than finds the action expects the main queue, that no queue or async thread hops occur. This prevents a slushy UI that is always updating asynchronously, and means the caller does not have to worry about the queue they are on, and nor does the Action.

However, it is important to not that this mechanism (using setSpecific/getSpecific) will not currently work if the Action’s queue uses a target queue. Trivia: the SmartDispatchQueue

  • Undocumented

    Declaration

    Swift

    public init()
  • Add an observer that will get notified about action start and end events.

    Note

    You can call this from any thread

    Declaration

    Swift

    public func add(observer: ActionDispatchObserver)
  • Perform the action, and track whether or not it was already completed by the time it returns, so whether sync or async, we know if completion should be called at some future point, so we can warn about this and maybe have a timeout in debug to catch occasions where this does not happen.

    Declaration

    Swift

    public func perform<FeatureType, ActionType>(request: ActionRequest<FeatureType, ActionType>, 
                                                 completion: Action.Completion) -> Action.Completion.Status