mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
27 lines
705 B
C#
27 lines
705 B
C#
using System.Diagnostics;
|
|
|
|
namespace Remotely.Shared.Helpers;
|
|
|
|
public static class WaitHelper
|
|
{
|
|
public static bool WaitFor(Func<bool> condition, TimeSpan timeout, int pollingMs = 10)
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
while (!condition() && sw.Elapsed < timeout)
|
|
{
|
|
Thread.Sleep(pollingMs);
|
|
}
|
|
return condition();
|
|
}
|
|
|
|
public static async Task<bool> WaitForAsync(Func<bool> condition, TimeSpan timeout, int pollingMs = 10)
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
while (!condition() && sw.Elapsed < timeout)
|
|
{
|
|
await Task.Delay(pollingMs).ConfigureAwait(false);
|
|
}
|
|
return condition();
|
|
}
|
|
}
|