Agent skill

handling-async-operations-lite

Provides essential async programming patterns with Task and ValueTask. Use when quickly referencing core async/await techniques without detailed explanations.

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/handling-async-operations-lite

SKILL.md

Async Programming Essentials

1. Task vs ValueTask

csharp
// General async: Use Task
public async Task<Data> LoadAsync() { }

// Frequent cache hits: Use ValueTask
public ValueTask<Data> GetAsync(string key)
{
    if (_cache.TryGetValue(key, out var cached))
        return new ValueTask<Data>(cached);

    return new ValueTask<Data>(LoadFromDbAsync(key));
}

2. CancellationToken

csharp
public async Task<Data> LoadAsync(CancellationToken ct = default)
{
    ct.ThrowIfCancellationRequested();
    return await _httpClient.GetFromJsonAsync<Data>(url, ct);
}

// Timeout
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
await LongOperationAsync(cts.Token);

3. Anti-patterns

csharp
// ❌ No async void
public async void BadMethod() { }

// ❌ No .Result, .Wait() (deadlock)
var result = GetDataAsync().Result;

// ✅ Use await
var result = await GetDataAsync();

For details: See /dotnet-async skill

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results