Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created August 3, 2022 00:24
Embed
What would you like to do?
class Client
{
public TimeSpan Timeout { get; }
public Client(TimeSpan timeout)
{
this.Timeout = timeout;
}
public async Task SendAsync(CancellationToken cancellationToken = default)
{
// Create concatenated new CancellationTokenSource
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(Timeout);
await SendCoreAsync(cts.Token);
}
// snip...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment