Created
August 3, 2022 00:24
-
-
Save neuecc/d606739ab3e8301918538a9bc5eb1ee0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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