Skip to content

Instantly share code, notes, and snippets.

@gregmac
Created August 18, 2021 22:34
Show Gist options
  • Save gregmac/6a1db684a034c09b33c65a8f5c84ec31 to your computer and use it in GitHub Desktop.
Save gregmac/6a1db684a034c09b33c65a8f5c84ec31 to your computer and use it in GitHub Desktop.
public static class TaskExtensions
{
public static async Task WaitSlowTask(this Task waitTask, TimeSpan slowTime, Action slowAction)
{
var taskCompleted = new CancellationTokenSource();
if (slowAction != null)
{
_ = Task.Delay(slowTime, taskCompleted.Token).ContinueWith(_ => slowAction.Invoke(), TaskContinuationOptions.OnlyOnRanToCompletion);
}
await waitTask.ConfigureAwait(false);
taskCompleted.Cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment