diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs index de0246628c..257662c112 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs @@ -67,6 +67,27 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS }); } + /// + /// Schedules an action to be executed. + /// + /// Scheduler to execute the action on. + /// A state object to be passed to . + /// Action to execute. + /// The disposable object used to cancel the scheduled action (best effort). + /// or is null. + // Note: The naming of that method differs because otherwise, the signature would cause ambiguities. + internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, Func action) + { + if (scheduler == null) + throw new ArgumentNullException(nameof(scheduler)); + if (action == null) + throw new ArgumentNullException(nameof(action)); + + return scheduler.Schedule( + (action, state), + (_, tuple) => tuple.action(tuple.state)); + } + /// /// Schedules an action to be executed after the specified relative due time. /// @@ -116,6 +137,26 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple)); } + /// + /// Schedules an action to be executed after the specified relative due time. + /// + /// Scheduler to execute the action on. + /// Action to execute. + /// A state object to be passed to . + /// Relative time after which to execute the action. + /// The disposable object used to cancel the scheduled action (best effort). + /// or is null. + internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, TimeSpan dueTime, Func action) + { + if (scheduler == null) + throw new ArgumentNullException(nameof(scheduler)); + if (action == null) + throw new ArgumentNullException(nameof(action)); + + // See note above. + return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple)); + } + /// /// Schedules an action to be executed at the specified absolute due time. /// @@ -165,6 +206,26 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple)); } + /// + /// Schedules an action to be executed after the specified relative due time. + /// + /// Scheduler to execute the action on. + /// Action to execute. + /// A state object to be passed to . + /// Relative time after which to execute the action. + /// The disposable object used to cancel the scheduled action (best effort). + /// or is null. + internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func action) + { + if (scheduler == null) + throw new ArgumentNullException(nameof(scheduler)); + if (action == null) + throw new ArgumentNullException(nameof(action)); + + // See note above. + return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple)); + } + /// /// Schedules an action to be executed. /// @@ -198,5 +259,10 @@ private static IDisposable Invoke(IScheduler scheduler, (TState state, A tuple.action(tuple.state); return Disposable.Empty; } + + private static IDisposable Invoke(IScheduler scheduler, (TState state, Func action) tuple) + { + return tuple.action(tuple.state); + } } }