ClosureChain

public class ClosureChain

ClosureChain simplifies sequential async completion methods for Swift. It provides a familiar try-catch pattern for sequential async methods.

  • Failures that may be sent to the catch block due to run-time errors

    See more

    Declaration

    Swift

    public enum Failures : LocalizedError
    extension ClosureChain.Failures: Equatable
  • Every ClosureChain has a single CatchHandler associated with it. If any errors are thrown within a try-block, or from ClosureChain itself due to usage errors, subsequent try-blocks will no longer be called and the CatchHandler will receive the associated Error.

    Declaration

    Swift

    public typealias CatchHandler = (Error) -> Void
  • Initialize a closure chain

    Declaration

    Swift

    public init()
  • Execute a block. Each try block will be executed sequentially with another.

    Declaration

    Swift

    public func `try`(_ completion: @escaping (Link) throws -> Void)

    Parameters

    completion

    Block to execute. This block must call either Link.success() or throw an error to continue the ClosureChain

  • Execute a block. Each try block will be executed sequentially with another.

    Declaration

    Swift

    public func `try`<RequiredType>(_ completion: @escaping (_ param: RequiredType, Link) throws -> Void)

    Parameters

    completion

    Block to execute. A parameter can be specified with type. This type must match exactly the type of the .success() call of a prior try block. This block must call either Link.success() or throw an error to continue the ClosureChain

  • Error handler. This error handler is called if any try-block has thrown an error (or if ClosureChain throws an error). No subsequent try-blocks will be executed.

    Declaration

    Swift

    public func `catch`(_ completion: @escaping CatchHandler)

    Parameters

    completion

    Error handler

  • This method must be called at some point after all try-blocks have been defined. No try-blocks will be executed otherwise.

    Declaration

    Swift

    public func start()
  • ClosureChain sequentially executes try-blocks, also known as Links. Links must receive exactly one of either a .success() or a .throw() to signfiy the completion of the Link.

    See more

    Declaration

    Swift

    class Link