namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;

internal static class ImpltestsBacklogAssertions
{
    public static void SpinWaitUntil(Func<bool> condition, TimeSpan timeout, TimeSpan? poll = null)
    {
        var deadline = DateTime.UtcNow + timeout;
        var interval = poll ?? TimeSpan.FromMilliseconds(10);
        while (DateTime.UtcNow < deadline)
        {
            if (condition())
                return;
            Thread.Sleep(interval);
        }
        throw new TimeoutException("Condition was not satisfied within the timeout.");
    }
}
