Skip to content

await unwraps the result

Context: await extracts the result from a Task<T> or ValueTask<T>, returning the underlying value. For Task, it waits for completion without returning a value.

using System.Threading.Tasks;
public class Example
{
public async Task<int> GetNumberAsync() => 42;
public async Task UseAsync()
{
Task<int> task = GetNumberAsync();
int result = await task; // unwraps the int
// result == 42
}
}

You would need to check IsCompleted, use continuations, or block with .Result.

Task<int> task = GetNumberAsync();
int result = task.Result; // blocks, dangerous

Chaining async calls: await makes sequential async calls natural.

var user = await GetUserAsync();
var orders = await GetOrdersAsync(user.Id);