// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Reactive.Disposables;
namespace System.Reactive.Concurrency
{
///
/// Provides a set of extension methods for virtual time scheduling.
///
public static class VirtualTimeSchedulerExtensions
{
///
/// Schedules an action to be executed at dueTime.
///
/// Absolute time representation type.
/// Relative time representation type.
/// Scheduler to execute the action on.
/// Relative time after which to execute the action.
/// Action to be executed.
/// The disposable object used to cancel the scheduled action (best effort).
/// or is null.
public static IDisposable ScheduleRelative(this VirtualTimeSchedulerBase scheduler, TRelative dueTime, Action action)
where TAbsolute : IComparable
{
if (scheduler == null)
throw new ArgumentNullException("scheduler");
if (action == null)
throw new ArgumentNullException("action");
return scheduler.ScheduleRelative(action, dueTime, Invoke);
}
///
/// Schedules an action to be executed at dueTime.
///
/// Absolute time representation type.
/// Relative time representation type.
/// Scheduler to execute the action on.
/// Absolute time at which to execute the action.
/// Action to be executed.
/// The disposable object used to cancel the scheduled action (best effort).
/// or is null.
public static IDisposable ScheduleAbsolute(this VirtualTimeSchedulerBase scheduler, TAbsolute dueTime, Action action)
where TAbsolute : IComparable
{
if (scheduler == null)
throw new ArgumentNullException("scheduler");
if (action == null)
throw new ArgumentNullException("action");
return scheduler.ScheduleAbsolute(action, dueTime, Invoke);
}
static IDisposable Invoke(IScheduler scheduler, Action action)
{
action();
return Disposable.Empty;
}
}
}