Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime,
return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
}

/// <summary>
/// Schedules an action to be executed after the specified relative due time.
/// </summary>
/// <param name="scheduler">Scheduler to execute the action on.</param>
/// <param name="action">Action to execute.</param>
/// <param name="state">A state object to be passed to <paramref name="action"/>.</param>
/// <param name="dueTime">Relative time after which to execute the action.</param>
/// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Action<TState> 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));
}

/// <summary>
/// Schedules an action to be executed at the specified absolute due time.
/// </summary>
Expand All @@ -95,6 +115,26 @@ public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset due
return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
}

/// <summary>
/// Schedules an action to be executed after the specified relative due time.
/// </summary>
/// <param name="scheduler">Scheduler to execute the action on.</param>
/// <param name="action">Action to execute.</param>
/// <param name="state">A state object to be passed to <paramref name="action"/>.</param>
/// <param name="dueTime">Relative time after which to execute the action.</param>
/// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Action<TState> 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));
}

/// <summary>
/// Schedules an action to be executed.
/// </summary>
Expand All @@ -117,5 +157,11 @@ private static IDisposable Invoke(IScheduler scheduler, Action action)
action();
return Disposable.Empty;
}

private static IDisposable Invoke<TState>(IScheduler scheduler, (TState state, Action<TState> action) tuple)
{
tuple.action(tuple.state);
return Disposable.Empty;
}
}
}