| | | 1 | | using System.Threading.Tasks; |
| | | 2 | | |
| | | 3 | | namespace AmbientServices.Utilities; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A static class that contains extensions for <see cref="Task"/>. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// <pitch>A <see cref="ValueTask{TResult}"/>-from-value shim: the equivalent of <c>ValueTask.FromResult</c> on target f |
| | | 10 | | /// </remarks> |
| | | 11 | | public static class TaskUtilities |
| | | 12 | | { |
| | | 13 | | #if NET5_0_OR_GREATER |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets a <see cref="ValueTask{TResult}"/> from the specified value. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <typeparam name="T">The type contained within the ValueTask.</typeparam> |
| | | 18 | | /// <param name="value">The value to encapsulate into the ValueTask.</param> |
| | | 19 | | /// <returns>A <see cref="ValueTask{TResult}"/> containing the specified result value.</returns> |
| | | 20 | | public static ValueTask<T> ValueTaskFromResult<T>(T value) |
| | | 21 | | { |
| | 2 | 22 | | return ValueTask.FromResult(value); |
| | | 23 | | } |
| | | 24 | | #else |
| | | 25 | | #pragma warning disable CS1998 |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets a <see cref="ValueTask{TResult}"/> from the specified value. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <typeparam name="T">The type contained within the ValueTask.</typeparam> |
| | | 30 | | /// <param name="value">The value to encapsulate into the ValueTask.</param> |
| | | 31 | | /// <returns>A <see cref="ValueTask{TResult}"/> containing the specified result value.</returns> |
| | | 32 | | public static async ValueTask<T> ValueTaskFromResult<T>(T value) |
| | | 33 | | { |
| | | 34 | | return value; |
| | | 35 | | } |
| | | 36 | | #pragma warning restore CS1998 |
| | | 37 | | #endif |
| | | 38 | | } |