// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System; using System.Reactive.Disposables; namespace System.Reactive.Concurrency { public static partial class Scheduler { /// /// Schedules an action to be executed. /// /// Scheduler to execute the action on. /// Action to execute. /// The disposable object used to cancel the scheduled action (best effort). /// or is null. public static IDisposable Schedule(this IScheduler scheduler, Action action) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (action == null) throw new ArgumentNullException("action"); return scheduler.Schedule(action, Invoke); } /// /// Schedules an action to be executed after the specified relative due time. /// /// Scheduler to execute the action on. /// Action to execute. /// Relative time after which to execute the action. /// The disposable object used to cancel the scheduled action (best effort). /// or is null. public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action action) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (action == null) throw new ArgumentNullException("action"); return scheduler.Schedule(action, dueTime, Invoke); } /// /// Schedules an action to be executed at the specified absolute due time. /// /// Scheduler to execute the action on. /// Action to execute. /// Absolute time at which to execute the action. /// The disposable object used to cancel the scheduled action (best effort). /// or is null. public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action action) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (action == null) throw new ArgumentNullException("action"); return scheduler.Schedule(action, dueTime, Invoke); } /// /// Schedules an action to be executed. /// /// Scheduler to execute the action on. /// Action to execute. /// The disposable object used to cancel the scheduled action (best effort). /// or is null. public static IDisposable ScheduleLongRunning(this ISchedulerLongRunning scheduler, Action action) { if (scheduler == null) throw new ArgumentNullException("scheduler"); if (action == null) throw new ArgumentNullException("action"); return scheduler.ScheduleLongRunning(action, (a, c) => a(c)); } static IDisposable Invoke(IScheduler scheduler, Action action) { action(); return Disposable.Empty; } } }