Created
August 18, 2021 22:34
-
-
Save gregmac/6a1db684a034c09b33c65a8f5c84ec31 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
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