TaskExtensions Class
Definition
Extension methods for the Task<TResult> class.
public static class TaskExtensions
- Inheritance
-
TaskExtensions
Examples
This example shows how to await a task that returns a sequence and keep only the single matching result.
using System.Collections.Generic;
using System.Threading.Tasks;
using Savvyio;
namespace ExampleApp;
public sealed class TaskExtensionsExample
{
public Task<OrderProjection?> LoadAsync()
{
Task<IEnumerable<OrderProjection>> query = Task.FromResult<IEnumerable<OrderProjection>>(new[] { new OrderProjection("ORD-42") });
return query.SingleOrDefaultAsync();
}
}
public sealed record OrderProjection(string OrderId);
Methods
| Name | Description |
|---|---|
| SingleOrDefaultAsync<T>(Task<IEnumerable<T>>) | Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence. |