Proposal: ITask and ITask<T> interfaces #8908
Replies: 1 comment 1 reply
-
This is an API request and should be made to the runtime repository. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, it can be very tricky to work with tasks in reflection. For example, if you have a
Task<T>
cast to anobject
, there is no way to get the result without reflection. Additionally, there is no way to handleTask
andValueTask
at the same time. AnITask
interface could solve both problems.Before
After
A proposal already exists to make
Task
covariant, meaningTask<string>
could be cast toTask<object>
. However, this proposal would also handleValueTask
, and any other type ofTask
added in the future.ITask
would look something like this:Both
Task
andValueTask
would inherit fromITask
. Additionally, asynchronous functions would be able to returnITask
instead ofTask
orValueTask
.Beta Was this translation helpful? Give feedback.
All reactions