parallelZip

CancellableTaskResult.parallelZip

Namespace: FsToolkit.ErrorHandling

Function Signature:

CancellableTaskResult<'left, 'Error>
  -> CancellableTaskResult<'right, 'Error>
  -> CancellableTaskResult<'left * 'right, 'Error>

Takes two CancellableTaskResult values, starts them concurrently, and returns a tuple of the results once both complete. If either computation returns an Error, that error is returned.

Unlike zip, both computations are started before waiting for either to complete, which can improve throughput when the two operations are independent.

Examples

Example 1

Fetching two independent resources in parallel:

let getUserAndPermissions (userId: UserId) : CancellableTaskResult<User * Permission list, string> =
    CancellableTaskResult.parallelZip
        (fetchUser userId)
        (fetchPermissions userId)

Example 2

Combining two concurrent API calls in a larger computation:

Example 3

Unlike zip, both tasks are started at the same time — neither is skipped even if the other returns an error first:

Last updated