Skip to content

Question: parallel async CE #333

Open

Description

@ursenzler

First, many thanks for the update.

I wondered what your thoughts are on a parallelAsyncCE? There exist parallelResultCE and parallelValidationCE, but no parallelAsyncCE.
Is it because there is no asyncCE because that is included in the F# Core libraries, or are there other reasons?

Happy coding, Urs

Activity

  1. njlr commented on Jun 13, 2025

    @njlr
    Contributor

    I think this would be a good addition since and! for the official async CE was rejected.

    There might be overlap with IcedTasks, however: https://github.com/TheAngryByrd/IcedTasks/blob/7c9ab05fc64e4f2dca99d130eae91a0243516cf8/src/IcedTasks/ParallelAsync.fs#L130-L133

    Note that there are several different ways to "zip" two asyncs. This library uses Async.Parallel, which is different to IcedTasks.

  2. ursenzler commented on Jun 13, 2025

    @ursenzler
    ContributorAuthor

    The different implementation possibilities are the reason why I'm not confident in implementing this correctly on my own. I don't know the implications of the different approaches.

  3. njlr commented on Jun 13, 2025

    @njlr
    Contributor

    You can use the Async.parallelMap2 implementation from this library with regular async:

    #r "nuget: FsToolkit.ErrorHandling, 5"
    
    open FsToolkit.ErrorHandling
    
    let foo =
      async {
        return 1
      }
    
    let bar =
      async {
        return 2
      }
    
    async {
      let! x, y = Async.parallelMap2 (fun x y -> x, y) foo bar
    
      return x + y
    }

    Or with CE syntax:

    #r "nuget: FsToolkit.ErrorHandling, 5"
    
    open FsToolkit.ErrorHandling
    
    type AsyncBuilder with
      member this.MergeSources(x, y) =
        Async.parallelMap2 (fun i j -> i, j) x y
    
    let foo =
      async {
        return 1
      }
    
    let bar =
      async {
        return 2
      }
    
    async {
      let! x = foo
      and! y = bar
    
      return x + y
    }
  4. TheAngryByrd commented on Jun 16, 2025

    @TheAngryByrd
    Collaborator

    Yeah, IcedTasks has an parallelAsync implementation, however it doesn't support Fable like FsToolkit does. I'll have to think about if it makes sense to put it here because of that.

    njlr's solution would work if you need it for Fable or you can used IcedTask's implementation.

  5. ursenzler commented on Jun 18, 2025

    @ursenzler
    ContributorAuthor

    We use the implementation of IcedTask in our own extension to the normal AsyncBuilder.
    I guess it would be nice to have a parallelAsync in FsToolkit, though.

  6. ursenzler commented on May 20, 2026

    @ursenzler
    ContributorAuthor

    Coming back to this. Does including a parallelAsync CE make sense to you? And if so, how to get it in there? I'd make a pull request, but CEs are really not my strong suit. I'd need a bit of help (Pair programming, Amplifying F# session, ...).

  7. ursenzler commented on May 20, 2026

    @ursenzler
    ContributorAuthor

    I found out that I can copy the ParallelAsyncBuilderBase from IcedTasks and add the MergeSources as proposed by @njlr
    The question remains whether you want the additional parallelAsync Builder in this library or not.

    I did some simple benchmarks to compare parallelism based on Async.parallel with the IcedTasks implementation. They are almost identical - around 0.2ns difference.

  8. TheAngryByrd commented on May 22, 2026

    @TheAngryByrd
    Collaborator

    Yeah, I think it can live in Fstoolkit proper. Probably doesnt require IcedTasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions