2024-02-10 17:12:26 +08:00
|
|
|
|
namespace MesETL.Shared.Helper;
|
2024-01-29 09:29:16 +08:00
|
|
|
|
|
|
|
|
|
public static class TaskExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task WaitUntil(Func<bool> condition, int pollDelay = 25, CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (!condition())
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(pollDelay, ct);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(TaskCanceledException)
|
|
|
|
|
{
|
|
|
|
|
// CancellationToken激活时Task.Delay通过抛异常来结束停止等待,不用管它
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|