fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
343 stars 20 forks source link

Add `Async.RaceAwait` to FSharp.Core #1261

Open Seng-Jik opened 1 year ago

Seng-Jik commented 1 year ago

I propose we add the these functions to FSharp.Core:

Pros and Cons

The advantages of making this adjustment to F# is having a useful function directly accessible in an idiomatic way without the need to resort to a package or using hand-written code.

The disadvantages of making this adjustment to F# is: Having more and more functions in the core library could make it harder for beginners to see the essentials.

Extra information

Estimated cost XS

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

For Readers

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

Tarmil commented 1 year ago

I guess this can be useful. Although assuming that the returned Async represents the still-running other computation, the semantics are more fitting for Task than Async.

vzarytovskii commented 1 year ago

Personally, I'm not entirely sure it has to be in the standard library, as opposed to just having it in nuget package.

Frassle commented 1 year ago

This pretty much already exists as Choice returning things like Choice<A,B> from it is a pretty thin wrapper. Doesn't feel like something that needs to be put into core.

Xyncgas commented 1 year ago

Async.Choice is a thing, which ever finishes first returning first

If you are implementing this api probably return a Task to represent on-going task that can be waited for its result, instead of returning async which is more like a specification in F#, of course you can wrap the result being waited in specification that specifies you can wait on it until result is available...

Functionally speaking, you produce a bunch of Task (not .NET task, task in general), checking whether the task has finished / value / result and iterate on them again clean up the rest of the tasks

cartermp commented 1 year ago

Yeah, my gut feel is this belongs in an async extensions library.

bartelink commented 1 year ago

FWIW there are some proposals in this space that are parked as TaskEx issues in https://github.com/fsprojects/FSharp.Control.TaskSeq/issues

Anything that joins that list should generally meet the bar of being applicable across Async/Task/ValueTask

dsyme commented 1 year ago

Has anyone got a sample implementation based on existing Async?