コード例 #1
0
 /// <summary>
 /// Schedules an action to be executed at dueTime.
 /// </summary>
 /// <param name="scheduler">Scheduler to execute the action on.</param>
 /// <param name="dueTime">Relative time after which to execute the action.</param><param name="action">Action to be executed.</param>
 /// <returns>
 /// The disposable object used to cancel the scheduled action (best effort).
 /// </returns>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
 public static IDisposable ScheduleRelative(
     [NotNull] this VirtualTimeScheduler <long, long> scheduler,
     TimeSpan dueTime,
     Action action)
 {
     return(scheduler.ScheduleRelative(dueTime.Ticks, action));
 }
コード例 #2
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            Ensure.NotNull(observer, nameof(observer));
            Subscriptions.Add(new Subscription(_scheduler.Clock));
            var index = Subscriptions.Count - 1;

            var d = new CompositeDisposable();

            foreach (var message in Messages)
            {
                var notification = message.Value;
                d.Add(_scheduler.ScheduleRelative(
                          default(object),
                          message.Time,
                          (_, __) => { notification.Accept(observer); return(Disposable.Empty); }));
            }

            return(Disposable.Create(() =>
            {
                Subscriptions[index] = new Subscription(Subscriptions[index].Subscribe, _scheduler.Clock);
                d.Dispose();
            }));
        }