internal async Task <TQuery> Get <TQuery>(ExpectTimeout timeout) where TQuery : Query { var pendingGet = null as TimedWait; lock (_updateLock) { if (IsInitial) { return((TQuery)_key.Type.New()); } if (IsLatest) { return((TQuery)_query); } pendingGet = timeout.ToTimedWait(); _pendingGet = pendingGet; } await pendingGet.Task; _pendingGet = null; return((TQuery)_query); }
public async Task <TEvent> Dequeue <TEvent>(ExpectTimeout timeout, bool scheduled) where TEvent : Event { if (_error != null) { throw new ExpectException($"Event {typeof(TEvent)} did not occur as expected", _error); } if (!_nextPoints.TryDequeue(out var nextPoint)) { _nextPointWait = timeout.ToTimedWait(); if (!_nextPoints.TryDequeue(out nextPoint)) { try { await _nextPointWait.Task; } catch (Exception error) { throw new ExpectException($"Event {typeof(TEvent)} did not occur as expected", error); } finally { _nextPointWait = null; } _nextPoints.TryDequeue(out nextPoint); } } if (nextPoint.Scheduled && !scheduled) { throw new ExpectException($"Expected an unscheduled event: {nextPoint}"); } else if (!nextPoint.Scheduled && scheduled) { throw new ExpectException($"Expected a scheduled event: {nextPoint}"); } else if (nextPoint.Event is TEvent e) { return(e); } else { throw new ExpectException($"Expected an event of type {typeof(TEvent)}, received {nextPoint.Type.DeclaredType}"); } }
internal async Task WaitForLatest(ExpectTimeout timeout) { var latestWait = null as TimedWait; lock (_updateLock) { if (IsLatest) { return; } latestWait = timeout.ToTimedWait(); _latestWait = latestWait; } await latestWait.Task; _latestWait = null; }
internal async Task ExpectDone(ExpectTimeout timeout) { var pendingDone = null as TimedWait; lock (_updateLock) { if (IsLatest && IsDone) { return; } pendingDone = timeout.ToTimedWait(); _pendingDone = pendingDone; } await pendingDone.Task; _pendingDone = null; }