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

Support optional input for MapAction #30434

Merged
3 commits merged into from
Feb 26, 2021
Merged

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Feb 24, 2021

  • Add support for optional input
  • Add support for ValueTask output
  • Pass HttpContext.RequestAborted to WriteAsJsonAsync(), WriteAsync(), ReadFromJsonAsync(), ReadFormAsync()

Addresses #30248

@ghost ghost added the area-servers label Feb 24, 2021
@Kahbazi
Copy link
Member Author

Kahbazi commented Feb 24, 2021

Ping @halter73!

@mkArtakMSFT mkArtakMSFT added the community-contribution Indicates that the PR has been added by a community member label Feb 24, 2021
@davidfowl
Copy link
Member

Pass HttpContext.RequestAborted to WriteAsJsonAsync(), WriteAsync(), ReadFromJsonAsync(), ReadFormAsync()

I'm not sure we want to do this. This will result in LOTS of allocations (see #30390).

@Kahbazi
Copy link
Member Author

Kahbazi commented Feb 25, 2021

Pass HttpContext.RequestAborted to WriteAsJsonAsync(), WriteAsync(), ReadFromJsonAsync(), ReadFormAsync()

I'm not sure we want to do this. This will result in LOTS of allocations (see #30390).

What if the HttpContext.RequestAborted is used in the user code? That would cause allocation too, right? Is it possible to have a state to see if a cts is created and then pass the HttpContext.RequestAborted to WriteAsync?

@davidfowl
Copy link
Member

We're going to make it cheap but not as part of this PR. We also don't pass the token anywhere except when doing big IO transfers (like copying files) so I'd leave it for now


void TestAction([FromRoute] int value)
public static IEnumerable<object[]> FromRouteOptionalResult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Any particular reason for using local functions for FromRouteResult but not FromRouteOptionalResult?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like local functions are not generating the optional parameter and handles then in compile time.
According to Sharplab.io, this code:

public void M()
{
    Test();
    void Test(int a = 2)
    {
    }
}

will be compiled to this:

public void M()
{
    <M>g__Test|0_0(2);
}

[CompilerGenerated]
internal static void <M>g__Test|0_0(int a)
{
}

Perhaps this is another feature that could be asked from C# team?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue filed: dotnet/roslyn#51518

I also requested that lambdas add support for optional parameters as part of the C# 10 lambda improvements: dotnet/csharplang#4451 (comment)

@ghost
Copy link

ghost commented Feb 26, 2021

Hello @halter73!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 1735db4 into dotnet:main Feb 26, 2021
@Kahbazi Kahbazi deleted the kahbazi/MapActionParameters branch February 26, 2021 20:50
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants