limit(_:_:)

public func limit<J>(_ maxParallel: Int, _ defineBlock: (SafeLink<B>) -> SafeLink<J>) -> SafeLink<J>

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 SafeLink 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.