Why is there no ManualResetValueTaskSourceCore that returns a plain ValueTask object. #116408
Replies: 2 comments 4 replies
-
Why not use regular
|
Beta Was this translation helpful? Give feedback.
-
I agree to what @MihaZupan wrote. So more or less for completeness when you don't want to use BTW: the AVTMB is used by Roslyn to generate the state machine, so it's way easier to just use async / await, as was already written before. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For Tasks you have
TaskCompletionSource
that returns aTask
TaskCompletionSource<T>
that returns aTask<T>
For ValueTask despite the fact there is a
ValueTask
object and aValueTask<T>
object.There is no ManualResetValueTaskSourceCore that can generate a ValueTask.
The reason I am asking is that I have a Source generator that wraps around an existing class adding logs to existing methods.
For async methods and methods retuning
Task
andTask<T>
the solution was using TaskCompletionSource.However, using
ManualResetValueTaskSourceCore<T>
did not work with ValueTypes because I cannot create the non-generic one.For example my solution for task looks like (task is returned by the wrapped method):
However the same solution for ValueTask will only work for the
ValueTask<>
variants:How can I achieve this for the non-generic ValueTask.
The workaround I found is to use the implementation for Tasks and return a
return new ValueTask(tcs.Task);
orreturn new ValueTask<T>(tcs.Task);
at the end. But that would defeat the purpose of using ValueTask, at least I think so.Beta Was this translation helpful? Give feedback.
All reactions