public Task AdvanceTo(int position) { var flag = new SyncFlag(position); Interlocked.Exchange(ref _syncFlag, flag)?.Canceled(); if (position == _syncPosition) { return(Task.CompletedTask); } else if (position < _syncPosition) { throw new InvalidOperationException("Thread is already at positon " + _syncPosition); } _syncEvent.Set(); return(flag.Wait()); }
public async Task AdvanceAndFreezeBefore(int position) { var flag = new SyncFlag(position); Interlocked.Exchange(ref _syncFlag, flag)?.Canceled(); if (position <= _syncPosition) { throw new InvalidOperationException("Thread is already at positon " + _syncPosition); } _syncEvent.Set(); var reached = flag.Wait(); var frozen = _current.Frozen(); await Task.WhenAny(reached, frozen); Assert.AreEqual(TaskStatus.WaitingForActivation, reached.Status); Assert.AreEqual(TaskStatus.RanToCompletion, frozen.Status); }