Is there an existing issue for this?
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.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Currently custom awaitables are not supported and it is marked as a
TODOin the code. Honestly, I don't have a use for this myself, I stick withTaskandValueTaskbut 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
AwaitableInfothat method can return is discarded. I propose that information is used to create a customAwaitablethat also implements everything required to be an awaitable very similarly toObjectMethodExecutorAwaitable. 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 usingExpression.Newand sent into aExecute[...]method so that we canawaitit.One thing I propose this intentionally doesn't support is is the input delegate has a
returnTypeofSystem.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 otherTask<>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.