branch(_:)

public func branch<C>(_ defineBlock: (Link<B>) -> Link<C>) -> Link<C>

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.

  • C

    Declaration

    Swift

    public func branch<C>(_ defineBlock: (Link<B>) -> Link<C>) -> Link<C>