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
Add ValueTask and ValueTask<T> to Promise conversion #1744
Conversation
Adds new `IsAwaitable` and `ConvertAwaitableToPromise` methods. `IsAwaitable` checks if a result is a `Task`. For .NET Standard 2.1/.NET targets, the method also checks if a result is `ValueTask` or `ValueTask<T>`. If a result is awaitable, `Call` now calls `ConvertAwaitableToPromise`. This method makes use of the existing `ConvertTaskToPromise` method for `Task`-based results. For .NET Standard 2.1/.NET targets, it also handles conversion of `ValueTask`/`ValueTask<T>` results into `Task`/`Task<T>` before calling `ConvertTaskToPromise`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clean and concise PR!
Would you be adverse to adding the System.Threading.Tasks.Extensions reference for .NET Framework and .NET Standard targets? Otherwise I can see the potential for confusion if someone is targeting .NET Framework and using I'm happy to work up another PR to do this btw. |
Not sure if |
* Support ValueTask/ValueTask<T> in modern targets Adds new `IsAwaitable` and `ConvertAwaitableToPromise` methods. `IsAwaitable` checks if a result is a `Task`. For .NET Standard 2.1/.NET targets, the method also checks if a result is `ValueTask` or `ValueTask<T>`. If a result is awaitable, `Call` now calls `ConvertAwaitableToPromise`. This method makes use of the existing `ConvertTaskToPromise` method for `Task`-based results. For .NET Standard 2.1/.NET targets, it also handles conversion of `ValueTask`/`ValueTask<T>` results into `Task`/`Task<T>` before calling `ConvertTaskToPromise`. * Add ValueTask/ValueTask<T> tests
* Support ValueTask/ValueTask<T> in modern targets Adds new `IsAwaitable` and `ConvertAwaitableToPromise` methods. `IsAwaitable` checks if a result is a `Task`. For .NET Standard 2.1/.NET targets, the method also checks if a result is `ValueTask` or `ValueTask<T>`. If a result is awaitable, `Call` now calls `ConvertAwaitableToPromise`. This method makes use of the existing `ConvertTaskToPromise` method for `Task`-based results. For .NET Standard 2.1/.NET targets, it also handles conversion of `ValueTask`/`ValueTask<T>` results into `Task`/`Task<T>` before calling `ConvertTaskToPromise`. * Add ValueTask/ValueTask<T> tests
This PR extends the work done in #1567 to add support for converting
ValueTask
andValueTask<T>
to promises.This support is only available for .NET Standard 2.1 and .NET (non-Framework) targets. Support for .NET Framework and .NET Standard 2.0 targets could be enabled by adding a reference to System.Threading.Tasks.Extensions.