Skip to content
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

F# sample, Async<T> as an awaitable type #31149

Open
Rick-Anderson opened this issue Nov 28, 2023 · 2 comments
Open

F# sample, Async<T> as an awaitable type #31149

Rick-Anderson opened this issue Nov 28, 2023 · 2 comments
Labels
code help wanted Sample code help wanted. doc-idea

Comments

@Rick-Anderson
Copy link
Contributor

Create sample here

See #31140

@Rick-Anderson Rick-Anderson added the code help wanted Sample code help wanted. label Nov 28, 2023
@Rick-Anderson
Copy link
Contributor Author

@brianrourkeboll would you be able to create the samples we can show in the docs?

@brianrourkeboll
Copy link

@Rick-Anderson Do you mean something like this?

Are there existing C# samples focusing on Task/ValueTask/Task<T>/ValueTask<T>-returning (as opposed to synchronous) endpoints? If so, I would think that any F# async samples should go alongside those. If not, I'm not sure we necessarily need to add ones for F#.

Updated treatment of Task<unit>/ValueTask<unit>(/Async<unit>)

I'm not sure it's necessarily worth calling out the updated treatment of Task<unit>/ValueTask<unit>/Async<unit> in the docs themselves—this change is more about consistency in the framework's treatment of Task<unit>/ValueTask<unit>/Async<unit> values and in bringing the framework's treatment of idiomatic F# in line with its treatment of idiomatic C#.

In F#, Task<unit>/ValueTask<unit> are idiomatically equivalent to non-generic/void-returning Task/ValueTask—in fact, there is no non-generic/void Async type in F#, and Async<unit> is used instead.

Basically, by adding support for Async<'T> in minimal APIs, a decision had to be made around how Async<unit> would be treated. The framework's treatment of Task<unit>/ValueTask<unit> were updated to be consistent with that, including in JSON serialization and OpenAPI schema generation.

I think it would probably be enough just to ensure that this change is mentioned in the release notes for 9.0.

Automatic awaiting of Async<'T>

For this change, on the other hand, in addition to including it in the release notes, it might be enough to update places like the following (surfaced here) in the docs to indicate the added support for F# Async<'T>:

Minimal endpoints support the following types of return values:
1. `string` - This includes `Task<string>` and `ValueTask<string>`.
1. `T` (Any other type) - This includes `Task<T>` and `ValueTask<T>`.
1. `IResult` based - This includes `Task<IResult>` and `ValueTask<IResult>`.

Minimal endpoints support the following types of return values:

- 1. `string` - This includes `Task<string>` and `ValueTask<string>`.
- 1. `T` (Any other type) - This includes `Task<T>` and `ValueTask<T>`.
- 1. `IResult` based - This includes `Task<IResult>` and `ValueTask<IResult>`.
+ 1. `string` - This includes `Task<string>`, `ValueTask<string>`, and `Async<string>` (in F#).
+ 1. `T` (Any other type) - This includes `Task<T>`, `ValueTask<T>`, and `Async<T>` (in F#).
+ 1. `IResult` based - This includes `Task<IResult>`, `ValueTask<IResult>`, and `Async<IResult>` (in F#).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code help wanted Sample code help wanted. doc-idea
Projects
None yet
Development

No branches or pull requests

3 participants