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
See morecatchblock due to run-time errorsDeclaration
-
Every
ClosureChainhas a singleCatchHandlerassociated with it. If any errors are thrown within a try-block, or fromClosureChainitself due to usage errors, subsequent try-blocks will no longer be called and theCatchHandlerwill receive the associatedError.Declaration
Swift
public typealias CatchHandler = (Error) -> Void -
Initialize a closure chain
Declaration
Swift
public init() -
Execute a block. Each
tryblock will be executed sequentially with another.Declaration
Swift
public func `try`(_ completion: @escaping (Link) throws -> Void)Parameters
completionBlock to execute. This block must call either
Link.success()orthrowan error to continue theClosureChain -
Execute a block. Each
tryblock will be executed sequentially with another.Declaration
Swift
public func `try`<RequiredType>(_ completion: @escaping (_ param: RequiredType, Link) throws -> Void)Parameters
completionBlock to execute. A parameter can be specified with type. This type must match exactly the type of the
.success()call of a priortryblock. This block must call eitherLink.success()orthrowan error to continue theClosureChain -
Error handler. This error handler is called if any try-block has thrown an error (or if
ClosureChainthrows an error). No subsequent try-blocks will be executed.Declaration
Swift
public func `catch`(_ completion: @escaping CatchHandler)Parameters
completionError 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() -
See moreClosureChainsequentially executes try-blocks, also known asLinks. Links must receive exactly one of either a.success()or a.throw()to signfiy the completion of theLink.Declaration
Swift
class Link
View on GitHub
ClosureChain Class Reference