public async Task NoDoubleTrigger()
        {
            var e = new AutoResetEventAsync(false);

            e.Set();
            await TaskHelpers.AssertTriggered(e.WaitAsync());

            await TaskHelpers.AssertNotTriggered(e.WaitAsync());
        }
        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);
        }
        public async Task DoubleCanncelled()
        {
            var  e          = new AutoResetEventAsync(false);
            var  src        = new CancellationTokenSource();
            Task waitAsync  = e.WaitAsync(src.Token);
            Task wait2Async = e.WaitAsync(src.Token);

            src.Cancel();
            await TaskHelpers.AssertCancelled(waitAsync);

            await TaskHelpers.AssertCancelled(wait2Async);
        }
        public async Task UncancellableTrigger()
        {
            var e = new AutoResetEventAsync(false);

            e.Set();
            await TaskHelpers.AssertTriggered(e.WaitAsync(CancellationToken.None));
        }
Example #5
0
        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 Precancelled()
        {
            var e   = new AutoResetEventAsync(false);
            var src = new CancellationTokenSource();

            src.Cancel();
            await TaskHelpers.AssertCancelled(e.WaitAsync(src.Token));
        }
        public async Task DelayTriggable()
        {
            var  e    = new AutoResetEventAsync(false);
            Task wait = e.WaitAsync();

            e.Set();
            await TaskHelpers.AssertTriggered(wait);
        }
        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 DelayCancelled()
        {
            var  e         = new AutoResetEventAsync(false);
            var  src       = new CancellationTokenSource();
            Task waitAsync = e.WaitAsync(src.Token);

            src.CancelAfter(TimeSpan.FromSeconds(TaskHelpers.WaitTime.TotalSeconds / 2));
            await TaskHelpers.AssertCancelled(waitAsync);
        }
 public async Task UnTriggered()
 {
     var e = new AutoResetEventAsync(false);
     await TaskHelpers.AssertNotTriggered(e.WaitAsync());
 }
 public async Task Triggered()
 {
     var e = new AutoResetEventAsync(true);
     await TaskHelpers.AssertTriggered(e.WaitAsync());
 }