New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sequential processing for a sequence of asyncs #706

isaacabraham opened this Issue Nov 20, 2018 · 6 comments


None yet
5 participants

isaacabraham commented Nov 20, 2018

Sequential processing for a sequence of asyncs

I propose we provide support for an equivalent of Async.Parallel, Async.Sequential, which enforces sequential processing of workflows. The signature would be the same as Async.Parallel i.e. Seq<Async<'T>> -> Async<'T []>.

Sequential processing is useful in many cases where you need to, for example, throttle a number of asynchronous computations to a certain size. For example, you have 100 messages but can only send one at a time. Async.Parallel cannot achieve this sort of behaviour as it would send all of them together. In addition, combined with Seq.chunkBySize, you can control throttling at a specific batch size using Parallel for inner batches and Sequential for the overall control flow.

The existing way of approaching this problem in F# is to manually implement a recursive function or otherwise. However, it's a general problem which I believe would be useful to have.

Pros and Cons

The advantages of making this adjustment to F# are that the utility of FSharp.Core increases.

The disadvantages of making this adjustment to F# are that there is another method on the Async type, and some users may not know the difference between Async.Sequential and Async.Parallel

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: (put links to related suggestions here)

I have implemented a (crude) sample which illustrates how this may look here as a starting point. It would be useful to know what it is missing as a way of moving this forward.

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

@isaacabraham isaacabraham changed the title from Allow sequential async processing to Allow sequential processing for a sequence of asyncs Nov 20, 2018


This comment has been minimized.


realvictorprm commented Nov 20, 2018

Sounds understandable to me 👍


This comment has been minimized.


dsyme commented Nov 20, 2018

It's reasonable to add this.


This comment has been minimized.


cartermp commented Nov 21, 2018

@isaacabraham We can use an RFC to discuss approaches to implementation.


This comment has been minimized.

isaacabraham commented Nov 21, 2018

Should I go ahead and create a basic RFC or is that something the language design team do?


This comment has been minimized.


cartermp commented Nov 21, 2018

@isaacabraham definitely feel free. We can discuss the general approach to implementation there.


This comment has been minimized.

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