Skip to content

Support and! for task based CE #1363

Closed
Closed
@Lanayx

Description

@Lanayx

I propose we add support and! for task based CE

The use case is the following - we need to load several pieces of data that are not interdependent to combine them and use further on in program. Rather than doing those calls sequentially one after another it is beneficial to perform those calls concurrently and continue when all the pieces are loaded - performance optimization.
Actually, this is even covered in documentation although not implemented https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/computation-expressions#and

So basically it would be possible to simplify this code

task {
    let tOne= getData1()
    let tTwo= getData2()
    let! results = Task.WhenAll([| tOne; tTwo|])
    let one = tOne.Result
    let two = tOne.Result
    ...
}

into this code

task {
    let! one = getData1()
    and! two = getData2()
    ...
}

More examples

The existing way of approaching this problem in F# is

  1. the first snippet from above
  2. starting all tasks first and them awaiting them one by one
task {
    let tOne = getData1()
    let tTwo = getData2()
    let! one = tOne
    let! two = tTwo
    ...
}

Pros and Cons

The advantages of making this adjustment to F# are clear and concise way to concurrently await multiple tasks

The disadvantages of making this adjustment to F# are i don't see disadvantages

Extra information

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

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick these items 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
  • This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
  • 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
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate

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

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions