question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Custom Awaitable Types in Minimal API's

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Currently custom awaitables are not supported and it is marked as a TODO in the code. Honestly, I don’t have a use for this myself, I stick with Task and ValueTask but they exist out there and it would be nice to support them.

Describe the solution you’d like

Since a lot of work is done on this line to test whether the type is awaitable but the AwaitableInfo that method can return is discarded. I propose that information is used to create a custom Awaitable that also implements everything required to be an awaitable very similarly to ObjectMethodExecutorAwaitable. I believe there would be two versions of this. One with a void result and one non-void result. We can also utilize generics to create this object to minimize boxing. That awaitable is created using Expression.New and sent into a Execute[...] method so that we can await it.

One thing I propose this intentionally doesn’t support is is the input delegate has a returnType of System.Object. Currently when objects have that return type it gets sent to this method. To support custom awaitables in that method we would have to utilize a lot of reflection each and every call and that would most likely slow down all the other Task<> and such calls so that it would be fine not supporting this for calls that have to go through the runtime to determine how to format their output.

Additional context

I have begun working on this but PR’s require an issue to exist. I’m not quite ready to create a PR because I need to make sure it’s fully tested but I am close.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
justindbaurcommented, Mar 5, 2022

@davidfowl Totally understand. That’s why I make it clear I don’t even use it. Just wanted to play with Expressions and duck typing! But thought I would propose it anyways.

0reactions
msftbot[bot]commented, Mar 8, 2022

We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support F# `Async<'T>` as an awaitable type in minimal APIs
I'd like to be able to return F# async values and have them awaited when using minimal APIs endpoints just as I can...
Read more >
Create responses in Minimal API applications
Learn how to create responses for minimal APIs in ASP.NET Core. ... Minimal endpoints support the following types of return values:.
Read more >
Minimal APIs quick reference
Provides a quick reference for minimal APIs. Is intended for experienced developers. For an introduction, see Tutorial: Create a minimal API ...
Read more >
How to use parameter binding in minimal APIs in ASP.NET ...
Custom model binding in minimal APIs​​ Custom model binding allows developers to define their own binding logic for complex data types or ...
Read more >
Exploring the new minimal API source generator
In this post I take a look at the new minimal API source generator added in .NET 8 preview 3 to support AOT,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found