VirtualTimeScheduler<TAbsolute, TRelative>
public abstract class VirtualTimeScheduler<TAbsolute, TRelative> : VirtualTimeSchedulerBase<TAbsolute, TRelative> where TAbsolute : IComparable<TAbsolute>
Base class for virtual time schedulers using a priority queue for scheduled items.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Reactive.Concurrency
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1,
1
})]
public abstract class VirtualTimeScheduler<[System.Runtime.CompilerServices.Nullable(0)] TAbsolute, [System.Runtime.CompilerServices.Nullable(2)] TRelative> : VirtualTimeSchedulerBase<TAbsolute, TRelative> where TAbsolute : IComparable<TAbsolute>
{
private readonly SchedulerQueue<TAbsolute> _queue = new SchedulerQueue<TAbsolute>();
protected VirtualTimeScheduler()
{
}
protected VirtualTimeScheduler(TAbsolute initialClock, IComparer<TAbsolute> comparer)
: base(initialClock, comparer)
{
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
protected override IScheduledItem<TAbsolute> GetNext()
{
lock (_queue) {
while (_queue.Count > 0) {
ScheduledItem<TAbsolute> scheduledItem = _queue.Peek();
if (!scheduledItem.IsCanceled)
return scheduledItem;
_queue.Dequeue();
}
}
return null;
}
public override IDisposable ScheduleAbsolute<[System.Runtime.CompilerServices.Nullable(2)] TState>(TState state, TAbsolute dueTime, Func<IScheduler, TState, IDisposable> action)
{
if (action == null)
throw new ArgumentNullException("action");
ScheduledItem<TAbsolute, TState> si = null;
Func<IScheduler, TState, IDisposable> action2 = delegate(IScheduler scheduler, TState state1) {
lock (this._queue) {
this._queue.Remove((ScheduledItem<TAbsolute>)si);
}
return action(scheduler, state1);
};
si = (ScheduledItem<TAbsolute, TState>)new ScheduledItem<TAbsolute, TState>((IScheduler)this, state, action2, dueTime, base.Comparer);
lock (this._queue) {
this._queue.Enqueue((ScheduledItem<TAbsolute>)si);
}
return si;
}
}
}