Link

@dynamicMemberLookup
final public class Link<B, E, P> : Executable<E> where E : Error, P : AsyncBlockPerformer

Undocumented

  • Primary chain form. All other forms translate into this form.

    Declaration

    Swift

    @discardableResult
    public func chain<C>(file: StaticString = #file,
                         line: UInt = #line,
                         functionDescription: String? = nil,
                         _ function: @escaping (B, @escaping (Result<C, E>) -> Void) -> Void) -> Link<C, E, P>

    Parameters

    function

    will be executed as a child link of this Link. Receives B (the result of this Link and generates C.

    Return Value

    The child link which has been added to this Link‘s child list. Children are executed in parallel. See Link’s description.

  • Primary chain form. All other forms translate into this form.

    Declaration

    Swift

    @discardableResult
    public func chain<C>(file: StaticString = #file,
                         line: UInt = #line,
                         functionDescription: String? = nil,
                         _ function: @escaping (B, @escaping (Result<C, Never>) -> Void) -> Void) -> Link<C, E, P>

    Parameters

    function

    will be executed as a child link of this Link. Receives B (the result of this Link and generates C.

    Return Value

    The child link which has been added to this Link‘s child list. Children are executed in parallel. See Link’s description.

  • Primary chain form. All other forms translate into this form.

    Declaration

    Swift

    @discardableResult
    public func chain<C, OtherE: Error>(file: StaticString = #file,
                                                             line: UInt = #line,
                                                             functionDescription: String? = nil,
                                                             _ function: @escaping (B, @escaping (Result<C, OtherE>) -> Void) -> Void) -> Link<C, Error, P>

    Parameters

    function

    will be executed as a child link of this Link. Receives B (the result of this Link and generates C.

    Return Value

    The child link which has been added to this Link‘s child list. Children are executed in parallel. See Link’s description.

  • finally creates a subchain which will be executed whether or not the proceeding chain errors. In the case that no error occurs in the proceeding chain, finally is executed after the final link of the chain, as though it had been directly appended there. In the case that an error, the subchain defined by finally will be executed after the error handler has finished.

    Example:

    HoneyBee.start { root in
       root.errorHandler(funcE)
           .chain(funcA)
           .finally { link in
               link.chain(funcZ)
           }
              .chain(funcB)
           .chain(funcC)
    }
    

    In the preceding example, if no error occurs then the functions will execute in this order: funcA, funcB, funcC, funcZ. The error handler, funcE will not be executed. If funcB produces an error, then execution is as follows: funcA, funcB, funcE, funcZ. The links after the error, (funcC), will not be executed.

    Declaration

    Swift

    @discardableResult
    public func finally(file: StaticString = #file, line: UInt = #line, _ defineBlock: (Link<B, E, P>) -> Void) -> Link<B, E, P>

    Parameters

    defineBlock

    context within which to define the finally chain.

    Return Value

    a Link with the same execution context as self, but with a finally chain registered.

  • Undocumented

    Declaration

    Swift

    public subscript(block: @escaping (B) -> Void) -> Link<Void, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(block: @escaping (B) -> R) -> Link<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(dynamicMember keyPath: KeyPath<B, R>) -> Link<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R>(dynamicMember keyPath: KeyPath<B, TripleArgFunction<X, Y, Z, R, E>>) -> AsyncTripleArgFunction<X, Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R>(dynamicMember keyPath: KeyPath<B, DoubleArgFunction<Y, Z, R, E>>) -> AsyncDoubleArgFunction<Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R>(dynamicMember keyPath: KeyPath<B, SingleArgFunction<Z, R, E>>) -> AsyncSingleArgFunction<Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(dynamicMember keyPath: KeyPath<B, ZeroArgFunction<R, E>>) -> AsyncZeroArgFunction<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R>(dynamicMember keyPath: KeyPath<B, BoundTripleArgFunction<X, Y, Z, R, E, P>>) -> AsyncTripleArgFunction<X, Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R>(dynamicMember keyPath: KeyPath<B, BoundDoubleArgFunction<Y, Z, R, E, P>>) -> AsyncDoubleArgFunction<Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R>(dynamicMember keyPath: KeyPath<B, BoundSingleArgFunction<Z, R, E, P>>) -> AsyncSingleArgFunction<Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(dynamicMember keyPath: KeyPath<B, BoundZeroArgFunction<R, E, P>>) -> AsyncZeroArgFunction<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R>(dynamicMember keyPath: KeyPath<B, TripleArgFunction<X, Y, Z, R, Never>>) -> AsyncTripleArgFunction<X, Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R>(dynamicMember keyPath: KeyPath<B, DoubleArgFunction<Y, Z, R, Never>>) -> AsyncDoubleArgFunction<Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R>(dynamicMember keyPath: KeyPath<B, SingleArgFunction<Z, R, Never>>) -> AsyncSingleArgFunction<Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(dynamicMember keyPath: KeyPath<B, ZeroArgFunction<R, Never>>) -> AsyncZeroArgFunction<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R>(dynamicMember keyPath: KeyPath<B, BoundTripleArgFunction<X, Y, Z, R, Never, P>>) -> AsyncTripleArgFunction<X, Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R>(dynamicMember keyPath: KeyPath<B, BoundDoubleArgFunction<Y, Z, R, Never, P>>) -> AsyncDoubleArgFunction<Y, Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R>(dynamicMember keyPath: KeyPath<B, BoundSingleArgFunction<Z, R, Never, P>>) -> AsyncSingleArgFunction<Z, R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R>(dynamicMember keyPath: KeyPath<B, BoundZeroArgFunction<R, Never, P>>) -> AsyncZeroArgFunction<R, E, P> { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, TripleArgFunction<X, Y, Z, R, OtherE>>) -> AsyncTripleArgFunction<X, Y, Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, DoubleArgFunction<Y, Z, R, OtherE>>) -> AsyncDoubleArgFunction<Y, Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, SingleArgFunction<Z, R, OtherE>>) -> AsyncSingleArgFunction<Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R, OtherE>(dynamicMember keyPath: KeyPath<B, ZeroArgFunction<R, OtherE>>) -> AsyncZeroArgFunction<R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<X, Y, Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, BoundTripleArgFunction<X, Y, Z, R, OtherE, P>>) -> AsyncTripleArgFunction<X, Y, Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Y, Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, BoundDoubleArgFunction<Y, Z, R, OtherE, P>>) -> AsyncDoubleArgFunction<Y, Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<Z, R, OtherE>(dynamicMember keyPath: KeyPath<B, BoundSingleArgFunction<Z, R, OtherE, P>>) -> AsyncSingleArgFunction<Z, R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    public subscript<R, OtherE>(dynamicMember keyPath: KeyPath<B, BoundZeroArgFunction<R, OtherE, P>>) -> AsyncZeroArgFunction<R, Error, P> where OtherE : Error { get }
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onResult(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (Result<B, E>) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onResult(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (Result<B, ErrorContext<E>>) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onCompletion(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (ErrorContext<E>?) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onCompletion(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (E?) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onError(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (ErrorContext<E>) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func onError(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (E) -> Void) -> Link<B, E, P>
  • Undocumented

    Declaration

    Swift

    public func handleError(file: StaticString = #file, line: UInt = #line, _ completion: @escaping (E) -> Void) -> Link<B, Never, P>
  • Undocumented

    Declaration

    Swift

    public func expect<OtherE>(_ other: OtherE.Type, file: StaticString = #file, line: UInt = #line) -> Link<B, OtherE, P> where E == Never, OtherE : Error
  • Undocumented

    Declaration

    Swift

    public func expect<OtherE>(_ other: OtherE.Type, file: StaticString = #file, line: UInt = #line) -> Link<B, Error, P> where OtherE : Error
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func chain<R>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, _ function: @escaping (B) -> R) -> Link<R, E, P>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func chain<R>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, _ function: @escaping (B) throws -> R) -> Link<R, Error, P>
  • insert inserts a value of any type into the chain data flow.

    Declaration

    Swift

    public func insert<C>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, _ c: C) -> Link<C, E, P>

    Parameters

    c

    Any value

    Return Value

    a Link whose child links will receive c as their function argument.

  • drop ignores “drops” the inbound value and returns a Link whose value is Void

    Declaration

    Swift

    public var drop: Link<Void, E, P> { get }

    Return Value

    a Link whose child links will receive Void as their function argument.

  • tunnel defines a subchain with whose value is ultimately discarded. The links within the tunnel subchain run sequentially before the link which is the return value of tunnel. tunnel returns a Link whose execution result B is the result the receiver link. Thus the value B “hides” or “goes under ground” while the subchain processes and “pops back up” when it is completed. For example:

     .insert(8)
     .tunnel { link in
        link.chain(intToString) //convert int to string
     }
     .chain(multiplyInt)
    

    In the example above insert results in an Int into the chain and that int is passed along to intToString which transform the value into a String. After the tunnel context has finished, the original value 8 (an Int) is passed to multiplyInt

    Declaration

    Swift

    public func tunnel<R, OtherE, OtherP>(file: StaticString = #file, line: UInt = #line, _ defineBlock: (Link<B, E, P>) -> Link<R, OtherE, OtherP>) -> Link<B, OtherE, P> where OtherE : Error, OtherP : AsyncBlockPerformer

    Parameters

    defineBlock

    a block which creates a subchain to be limited.

    Return Value

    a Link whose execution result R is discarded.

  • Yields self to a new definition block. Within the block the caller may invoke chaining methods on block multiple times, thus achieving parallel chains. Example:

    link.branch { stem in
      stem.chain(func1)
          .chain(func2)
    
      stem.chain(func3)
          .chain(func4)
    }
    

    In the preceding example, when link is executed it will start the links containing func1 and func3 in parallel. func2 will execute when func1 is finished. Likewise func4 will execute when func3 is finished.

    Declaration

    Swift

    public func branch(_ defineBlock: (Link<B, E, P>) -> Void)

    Parameters

    defineBlock

    the block to which this Link yields itself.

  • Yields self to a new definition block. Within the block the caller may invoke chaining methods on block multiple times, thus achieving parallel chains. Example:

    link.branch { stem in
      let a = stem.chain(func1)
                  .chain(func2)
    
      let b = stem.chain(func3)
                  .chain(func4)
    
       return (a + b) // operator for .conjoin
    }
    .chain(combine)
    

    In the preceding example, when link is executed it will start the links containing func1 and func3 in parallel. func2 will execute when func1 is finished. Likewise func4 will execute when func3 is finished.

    Declaration

    Swift

    @discardableResult
    public func branch<C, OtherE, OtherP>(_ defineBlock: (Link<B, E, P>) -> Link<C, OtherE, OtherP>) -> Link<C, OtherE, OtherP> where OtherE : Error, OtherP : AsyncBlockPerformer

    Parameters

    defineBlock

    the block to which this Link yields itself.

    Return Value

    The link which is returned from defineBlock

  • Yields self to a new definition block. Within the block the caller may invoke chaining methods on block multiple times, thus achieving parallel chains. Example:

    link.branch { stem in
      let a = stem.chain(func1)
                  .chain(func2)
    
      let b = stem.chain(func3)
                  .chain(func4)
    
       return (a + b) // operator for .conjoin
    }
    .chain(combine)
    

    In the preceding example, when link is executed it will start the links containing func1 and func3 in parallel. func2 will execute when func1 is finished. Likewise func4 will execute when func3 is finished.

    Declaration

    Swift

    @discardableResult
    public func branch<C>(_ defineBlock: (Link<B, E, P>) -> Link<C, E, P>) -> Link<C, E, P>

    Parameters

    defineBlock

    the block to which this Link yields itself.

    Return Value

    The link which is returned from defineBlock

  • conjoin is a compliment to branch. Within the context of a branch it is natural and expected to create parallel execution chains. If the process definition wishes at some point to combine the results of these execution chains, then conjoin should be used. conjoin returns a Link which waits for both the receiver and the argument Links created results. Those results are combined into a tuple (B,C) which is passed to the child links of the returned Link

    Declaration

    Swift

    public func conjoin<C>(_ other: Link<C, E, P>) -> Link<(B, C), E, P>

    Parameters

    other

    the Link to join with

    Return Value

    A Link which combines the receiver and the arguments results.

  • conjoin is a compliment to branch. Within the context of a branch it is natural and expected to create parallel execution chains. If the process definition wishes at some point to combine the results of these execution chains, then conjoin should be used. conjoin returns a Link which waits for both the receiver and the argument Links created results. Those results are combined into a tuple (X, Y, C) which is passed to the child links of the returned Link

    Declaration

    Swift

    public func conjoin<X, Y, C>(_ other: Link<C, E, P>) -> Link<(X, Y, C), E, P> where B == (X, Y)

    Parameters

    other

    the Link to join with

    Return Value

    A Link which combines the receiver and the arguments results.

  • conjoin is a compliment to branch. Within the context of a branch it is natural and expected to create parallel execution chains. If the process definition wishes at some point to combine the results of these execution chains, then conjoin should be used. conjoin returns a Link which waits for both the receiver and the argument Links created results. Those results are combined into a tuple (X, Y, Z, C) which is passed to the child links of the returned Link

    Declaration

    Swift

    public func conjoin<X, Y, Z, C>(_ other: Link<C, E, P>) -> Link<(X, Y, Z, C), E, P> where B == (X, Y, Z)

    Parameters

    other

    the Link to join with

    Return Value

    A Link which combines the receiver and the arguments results.

  • Returns a new link with the given AsyncBlockperformer. N.B. this does not change the execution queue for the receiver’s function. Example

    HoneyBee.start(on: .main) { root in
       root.setErrorHandlder(handleError)
           .chain(funcA)
           .move(to: DispatchQueue.global())
           .chain(funcB)
    }
    

    In the preceding example, funcA will run on DispatchQueue.main and funcB will run on DispatchQueue.global()

    Declaration

    Swift

    public func move<OtherP>(to otherPerformer: OtherP, file: StaticString = #file, line: UInt = #line) -> Link<B, E, OtherP> where OtherP : AsyncBlockPerformer

    Parameters

    otherPerformer

    the new AsyncBlockPerformer for child link

    Return Value

    the receiver

  • limit defines a subchain with special runtime protections. The links within the limit subchain are guaranteed to have at most maxParallel parallel executions. limit is particularly useful in the context of a fully parallel process when part of the process must access a limited resource pool such as CPU execution contexts or network resources. This method returns a Link whose execution result J is the result of the final link of the subchain. This permits the chain to proceed naturally after limit. For example:

     .limit(5) { link in
        link.chain(resourceLimitedIntGenerator)
    }
    .chain(multiplyInt)
    

    In the example above resourceLimitedIntGenerator results in an Int and that int is passed along to multipyInt after the limit context has finished.

    Declaration

    Swift

    @discardableResult
    public func limit<J, OtherE, OtherP>(_ maxParallel: Int, _ defineBlock: (Link<B, E, P>) -> Link<J, OtherE, OtherP>) -> Link<J, OtherE, OtherP> where OtherE : Error, OtherP : AsyncBlockPerformer

    Parameters

    maxParallel

    the maximum number of parallel executions permitted for the subchains defined by defineBlock

    defineBlock

    a block which creates a subchain to be limited.

    Return Value

    a Link whose execution result J is the result of the final link of the subchain.

  • retry defines a subchain with special runtime properties. The defined subchain will execute a maximum of maxTimes + 1 times in an attempt to reach a non-error result. If each of the maxTimes + 1 attempts result in error, the error from the last-attempted pass will be send to the registered error handler. If any of the attempts succeeds, the result R will be forwarded to the link which is returned from this function. For example:

     .retry(2) { link in
        link.chain(transientlyFailingIntGenerator)
    }
    .chain(multiplyInt)
    

    In the example above transientlyFailingIntGenerator is a function which can fail in non-fatal ways. When it succeeds, the result is an Int and that int is passed to multiplyInt after the retry.

    Declaration

    Swift

    @discardableResult
    public func retry<R>(_ maxTimes: Int, _ defineBlock: @escaping (Link<B, E, P>) -> Link<R, E, P>) -> Link<R, E, P>

    Parameters

    maxTimes

    the maximum number of times to reattempt the subchain. Thus the subchain is executed at most maxTimes + 1

    defineBlock

    a block which creates a subchain to be retried.

    Return Value

    a Link whose execution result R is the result of the final link of the subchain.

Available where E == Never

Available where B : Collection, E: FailureRateAwareError

  • When the inbound type is a Collection, you may call map to asynchronously map over the elements of B in parallel, transforming them with transform subchain.

    Declaration

    Swift

    public func map<C>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, limit: Int? = nil, acceptableFailure: FailureRate = .none, _ transform: @escaping (Link<B.Iterator.Element, E, P>) -> Link<C, E, P>) -> Link<[C], E, P>

    Parameters

    transform

    the transformation subchain defining block which converts B.Iterator.Element to C

    Return Value

    a Link which will yield an array of Cs to it’s child links.

  • When the inbound type is a Collection, you may call filter to asynchronously filter the elements of B in parallel, using filter subchain

    Declaration

    Swift

    public func filter(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, limit: Int? = nil, acceptableFailure: FailureRate = .none, _ filter: @escaping (Link<B.Iterator.Element, E, P>) -> Link<Bool, E, P>) -> Link<[B.Iterator.Element], E, P>

    Parameters

    filter

    the filter subchain which produces a Bool

    Return Value

    a Link which will yield to it’s child links an array containing those B.Iterator.Elements which filter approved.

  • When the inbound type is a Collection, you may call each Each accepts a define block which creates a subchain which will be invoked once per element of the sequence. The Link which is given as argument to the define block will pass to its child links the element of the collection which is currently being processed.

    Declaration

    Swift

    @discardableResult
    public func each<R>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, limit: Int? = nil, acceptableFailure: FailureRate = .none, _ defineBlock: @escaping (Link<B.Element, E, P>) -> Link<R, E, P>) -> Link<[B.Element], E, P>

    Parameters

    defineBlock

    a block which creates a subchain for each element of the Collection

    Return Value

    a Link which will pass an Array of the nonfailing elements of B to its child links

  • When the inbound type is a Collection, you may call reduce Reduce accepts a define block which creates a subchain which will be executed sequentially, once per element of the sequence. The result of each successive execution of the subchain will be forwarded to the next pass of the subchain. The result of the final execution of the subchain will be forwarded to the returned link.

    Declaration

    Swift

    public func reduce<T>(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, with t: T, acceptableFailure: FailureRate = .none, _ defineBlock: @escaping (Link<(T, B.Element), E, P>) -> Link<T, E, P>) -> Link<T, E, P>

    Return Value

    a Link which will pass the result of the reduce to its child links.

  • When the inbound type is a Collection, you may call reduce Reduce accepts a define block which creates a subchain which will be executed in parallel, with up to N/2 other subchains. Each subchain combines two B.Elements into one B.Element. The result of each combination is again combined until a single value remains. This value is forwarded to the returned link.

    Declaration

    Swift

    public func reduce(file: StaticString = #file, line: UInt = #line, functionDescription: String? = nil, _ defineBlock: @escaping (Link<(B.Element, B.Element), E, P>) -> Link<B.Element, E, P>) -> Link<B.Element, E, P>

    Parameters

    defineBlock

    a block which creates a subchain to combined two elements of the Collection

    Return Value

    a Link which will pass the final combined result of the reduce to its child links.