Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rd-net/Lifetimes/Collections/Viewable/IScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public interface IRunWhileScheduler : IScheduler
/// </summary>
/// <param name="condition">A delegate to be executed over and over while it returns true.</param>
/// <param name="timeout">Maximum time to spend pumping. Use <see cref="TimeSpan.MaxValue"/> for no limit.</param>
/// <param name="throwOnTimeout">If true, throws when timeout elapses; if false, returns false on timeout.</param>
/// <returns>True if the condition was reached (condition returned false), false if timeout elapsed (when throwOnTimeout is false).</returns>
bool RunWhile(Func<bool> condition, TimeSpan timeout, bool throwOnTimeout = false);
bool RunWhile(Func<bool> condition, TimeSpan timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,14 @@ private void Run()
}
}

public bool RunWhile(Func<bool> condition, TimeSpan timeout, bool throwOnTimeout = false)
public bool RunWhile(Func<bool> condition, TimeSpan timeout)
{
var stopwatch = timeout == TimeSpan.MaxValue ? null : Stopwatch.StartNew();

while (condition())
{
if (stopwatch != null && stopwatch.Elapsed >= timeout)
{
if (throwOnTimeout)
throw new TimeoutException($"RunWhile timed out after {timeout}. Elapsed: {stopwatch.Elapsed}.");
{
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void Execute(Action action)
public bool IsActive => ourActive > 0;
public bool OutOfOrderExecution => false;

public bool RunWhile(Func<bool> condition, TimeSpan timeout, bool throwOnTimeout = false)
public bool RunWhile(Func<bool> condition, TimeSpan timeout)
{
// SynchronousScheduler executes actions inline when queued, so by the time
// RunWhile is called the condition is typically already satisfied.
Expand All @@ -51,8 +51,6 @@ public bool RunWhile(Func<bool> condition, TimeSpan timeout, bool throwOnTimeout
{
if (stopwatch != null && stopwatch.Elapsed >= timeout)
{
if (throwOnTimeout)
throw new TimeoutException($"RunWhile timed out after {timeout}. Elapsed: {stopwatch.Elapsed}.");
return false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions rd-net/RdFramework/Impl/RdSimpleDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ public void Queue(Action action)
myEvent.Set();
}

public bool RunWhile(Func<bool> condition, TimeSpan timeout, bool throwOnTimeout = false)
public bool RunWhile(Func<bool> condition, TimeSpan timeout)
{
var stopwatch = timeout == TimeSpan.MaxValue ? (LocalStopwatch?)null : LocalStopwatch.StartNew();

while (condition())
{
if (stopwatch.HasValue && stopwatch.Value.Elapsed >= timeout)
{
if (throwOnTimeout)
throw new TimeoutException($"RunWhile timed out after {timeout}. Elapsed: {stopwatch.Value.Elapsed}.");
return false;
}

Expand Down
Loading