public async Task Triggable() { var e = new AutoResetEventAsync(false); e.Set(); await TaskHelpers.AssertTriggered(e.WaitAsync()); }
public async Task UncancellableTrigger() { var e = new AutoResetEventAsync(false); e.Set(); await TaskHelpers.AssertTriggered(e.WaitAsync(CancellationToken.None)); }
private async Task ObserveRecordsAsync(IObserver <Record> observer, CancellationToken cancellationToken) { var statusChanged = new AutoResetEventAsync(true); var index = 0; using (this.status.Subscribe(_ => statusChanged.Set())) while (!cancellationToken.IsCancellationRequested) { await statusChanged.WaitAsync(cancellationToken); for (; index < this.segments.Count; index++) { cancellationToken.ThrowIfCancellationRequested(); var currentIndex = index; var record = await this.ReadRecordAsync(currentIndex, cancellationToken); if (record != null) { observer.OnNext(record); } } } }
public async Task CancellableTrigger() { var e = new AutoResetEventAsync(false); var src = new CancellationTokenSource(); e.Set(); await TaskHelpers.AssertTriggered(e.WaitAsync(src.Token)); }
public async Task DoubleTriggered() { var e = new AutoResetEventAsync(false); Task waitAsync = e.WaitAsync(); Task wait2Async = e.WaitAsync(); e.Set(); await TaskHelpers.AssertTriggered(waitAsync); await TaskHelpers.AssertNotTriggered(wait2Async); }