Skip to content

Commit

Permalink
Wait: Add while with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lionaneesh authored Dec 16, 2024
1 parent 006c889 commit c21bd58
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Core/GoalsComponent/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ public void While(Func<bool> condition)
Update();
}
}

public void WhileWithTimeout(Func<bool> condition, int timeoutMs) {
DateTime start = DateTime.UtcNow;
float elapsedMs;
while ((elapsedMs = (float)(DateTime.UtcNow - start).TotalMilliseconds) < timeoutMs && condition())
{
Update();
}
}
}

0 comments on commit c21bd58

Please sign in to comment.