Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created August 3, 2022 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuecc/d606739ab3e8301918538a9bc5eb1ee0 to your computer and use it in GitHub Desktop.
Save neuecc/d606739ab3e8301918538a9bc5eb1ee0 to your computer and use it in GitHub Desktop.
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