WaitWhile`T.cs 607 B

1234567891011121314151617181920212223242526
  1. using System;
  2. namespace UnityAsync
  3. {
  4. public struct WaitWhile<TState> : IAwaitInstruction
  5. {
  6. readonly Func<TState, bool> condition;
  7. readonly TState state;
  8. bool IAwaitInstruction.IsCompleted() => !condition(state);
  9. /// <summary>
  10. /// Waits until the condition returns true before continuing.
  11. /// </summary>
  12. public WaitWhile(TState state, Func<TState, bool> condition)
  13. {
  14. #if UNITY_EDITOR
  15. if(condition == null)
  16. throw new ArgumentNullException(nameof(condition), "This check only occurs in edit mode.");
  17. #endif
  18. this.condition = condition;
  19. this.state = state;
  20. }
  21. }
  22. }