mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 13:02:51 +08:00
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace Ocelot.UnitTests
|
|
{
|
|
public class Waiter
|
|
{
|
|
private readonly int _milliSeconds;
|
|
|
|
public Waiter(int milliSeconds)
|
|
{
|
|
_milliSeconds = milliSeconds;
|
|
}
|
|
|
|
public bool Until(Func<bool> condition)
|
|
{
|
|
var stopwatch = Stopwatch.StartNew();
|
|
var passed = false;
|
|
while (stopwatch.ElapsedMilliseconds < _milliSeconds)
|
|
{
|
|
if (condition.Invoke())
|
|
{
|
|
passed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return passed;
|
|
}
|
|
|
|
public bool Until<T>(Func<bool> condition)
|
|
{
|
|
var stopwatch = Stopwatch.StartNew();
|
|
var passed = false;
|
|
while (stopwatch.ElapsedMilliseconds < _milliSeconds)
|
|
{
|
|
if (condition.Invoke())
|
|
{
|
|
passed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return passed;
|
|
}
|
|
}
|
|
}
|