public async Task DoSomethingAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
CancellationTokenSource timeoutCancellationTokenSource = new();
timeoutCancellationTokenSource.CancelAfter(timeout);
// Create someCombinedCancellationToken which will cancel if either cancellationToken is cancelled
// or timeoutCancellationTokenSource is triggered
await DoSomethingElseAsync(someCombinedCancellationToken);
}
public async Task DoSomethingAsync(TimeSpan timeout, CancellationToken cancellationToken)
{
CancellationTokenSource timeoutCancellationTokenSource = new();
timeoutCancellationTokenSource.CancelAfter(timeout);
// Create someCombinedCancellationToken which will cancel if either cancellationToken is cancelled
// or timeoutCancellationTokenSource is triggered
await DoSomethingElseAsync(someCombinedCancellationToken);
}