SequenceProcessor

class SequenceProcessor<Context>
extension SequenceProcessor : CheckoutProcess where Context == State

The SequenceProcessor is designed to take a list of callback instances and execute the first one while providing it the ability to execute the next item in the list. This style of sequencing allows for truly asynchronous execution with each closure either passing the Next instance off to another function or class to be executed later or to be ignored if logic in that step indicates that progress should not continue.

Each closure must execute the Next closure for the chain to continue. Passing an error to the closure will cause execution to halt.

  • A convenient alias for the callback.

    Declaration

    Swift

    typealias Callback = Step<Context>
  • The next function supplied to each and every Callback instance

    Declaration

    Swift

    typealias Next = (Error?) -> Void
  • If such a listener is added, it will receive the Callback about to be executed. It must either return this Callback or another in its place.

    Declaration

    Swift

    typealias PreFireListener = (SequenceProcessor<Context>.Callback, Context?) -> SequenceProcessor<Context>.Callback
  • Array of Callback items that are to be processed sequentially

    Declaration

    Swift

    var callbacks: [SequenceProcessor<Context>.Callback]
  • Initializes a new SequenceProcessor with the supplied list of items to process. Each callback is called in sequence.

    Declaration

    Swift

    init(_ items: [SequenceProcessor<Context>.Callback] = [], queue: DispatchQueue? = nil)
  • A sequential list of Callback parsers that will have a chance to modify or swap out the next executing Callback in the list

    Declaration

    Swift

    var listeners: [SequenceProcessor<Context>.PreFireListener]
  • A sequence that will be started after all callbacks including postSequenceCallback are executed

    Declaration

    Swift

    var nextSequence: SequenceProcessor<Context>?
  • A queue to execute all callbacks and listeners on. If nil then current queue will be used.

    Declaration

    Swift

    let queue: DispatchQueue?

Available where Context == State

  • Adds item to this Checkout process at the end of the list

    Declaration

    Swift

    func append(_ item: SequenceProcessor<Context>.Callback)
  • Returns index of item with specified itemType in this Checkout process or nil if it’s not found

    Declaration

    Swift

    func index(of itemType: SequenceProcessor<Context>.Callback.Type) -> Int?
  • Inserts item to this Checkout process at the specified index

    Declaration

    Swift

    func insert(_ item: SequenceProcessor<Context>.Callback, at index: Int)
  • Removes item from this Checkout process as the specified index and returns the removed item

    Declaration

    Swift

    func remove(at index: Int) -> SequenceProcessor<Context>.Callback