diff options
author | Atsushi Eno <atsushieno@veritas-vos-liberabit.com> | 2012-11-12 22:47:31 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@veritas-vos-liberabit.com> | 2012-11-12 22:52:17 +0400 |
commit | d1174f3f8979321a9182925df460e07e08157b41 (patch) | |
tree | d16fb2fc191bf68ff0e2aac600adf71aba8cad01 /Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency | |
parent | d90a52595e24b1216c89f6cb5f245262db1810ae (diff) |
partial import of ca05fdeb565e: Reactive Extensions OSS V1.0
Diffstat (limited to 'Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency')
6 files changed, 156 insertions, 0 deletions
diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduledItem.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduledItem.cs new file mode 100644 index 0000000..ebb4879 --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduledItem.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +namespace System.Reactive.Concurrency +{ + /// <summary> + /// Represents a work item that has been scheduled. + /// </summary> + /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam> + public interface IScheduledItem<TAbsolute> + { + /// <summary> + /// Gets the absolute time at which the item is due for invocation. + /// </summary> + TAbsolute DueTime { get; } + + /// <summary> + /// Invokes the work item. + /// </summary> + void Invoke(); + } +} diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduler.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduler.cs new file mode 100644 index 0000000..1c837f0 --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IScheduler.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +namespace System.Reactive.Concurrency +{ + /// <summary> + /// Represents an object that schedules units of work. + /// </summary> + public interface IScheduler + { + /// <summary> + /// Gets the scheduler's notion of current time. + /// </summary> + DateTimeOffset Now { get; } + + /// <summary> + /// Schedules an action to be executed. + /// </summary> + /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> + /// <param name="state">State passed to the action to be executed.</param> + /// <param name="action">Action to be executed.</param> + /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> + IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action); + + /// <summary> + /// Schedules an action to be executed after dueTime. + /// </summary> + /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> + /// <param name="state">State passed to the action to be executed.</param> + /// <param name="action">Action to be executed.</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> + IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action); + + /// <summary> + /// Schedules an action to be executed at dueTime. + /// </summary> + /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> + /// <param name="state">State passed to the action to be executed.</param> + /// <param name="action">Action to be executed.</param> + /// <param name="dueTime">Absolute time at which to execute the action.</param> + /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> + IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action); + } +}
\ No newline at end of file diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerLongRunning.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerLongRunning.cs new file mode 100644 index 0000000..7d076b1 --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerLongRunning.cs @@ -0,0 +1,26 @@ +// 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 +{ + /// <summary> + /// Scheduler with support for starting long-running tasks. + /// This type of scheduler can be used to run loops more efficiently instead of using recursive scheduling. + /// </summary> + public interface ISchedulerLongRunning + { + /// <summary> + /// Schedules a long-running piece of work. + /// </summary> + /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> + /// <param name="state">State passed to the action to be executed.</param> + /// <param name="action">Action to be executed.</param> + /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> + /// <remarks> + /// <para><b>Notes to implementers</b></para> + /// The returned disposable object should not prevent the work from starting, but only set the cancellation flag passed to the specified action. + /// </remarks> + IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action); + } +}
\ No newline at end of file diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerPeriodic.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerPeriodic.cs new file mode 100644 index 0000000..825a748 --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/ISchedulerPeriodic.cs @@ -0,0 +1,23 @@ +// 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 +{ + /// <summary> + /// Scheduler with support for running periodic tasks. + /// This type of scheduler can be used to run timers more efficiently instead of using recursive scheduling. + /// </summary> + public interface ISchedulerPeriodic + { + /// <summary> + /// Schedules a periodic piece of work. + /// </summary> + /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> + /// <param name="state">Initial state passed to the action upon the first iteration.</param> + /// <param name="period">Period for running the work periodically.</param> + /// <param name="action">Action to be executed, potentially updating the state.</param> + /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns> + IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action); + } +} diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatch.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatch.cs new file mode 100644 index 0000000..1b482ab --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatch.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System; + +namespace System.Reactive.Concurrency +{ + /// <summary> + /// Abstraction for a stopwatch to compute time relative to a starting point. + /// </summary> + public interface IStopwatch + { + /// <summary> + /// Gets the time elapsed since the stopwatch object was obtained. + /// </summary> + TimeSpan Elapsed { get; } + } +} diff --git a/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatchProvider.cs b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatchProvider.cs new file mode 100644 index 0000000..6a0d2a5 --- /dev/null +++ b/Rx.NET/System.Reactive.Interfaces/Reactive/Concurrency/IStopwatchProvider.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System; + +namespace System.Reactive.Concurrency +{ + /* + * The ability to request a stopwatch object has been introduced in Rx v2.0 to reduce the + * number of allocations made by operators that use absolute time to compute relative time + * diffs, such as TimeInterval and Delay. This causes a large number of related objects to + * be allocated in the BCL, e.g. System.Globalization.DaylightTime. + */ + + /// <summary> + /// Provider for IStopwatch objects. + /// </summary> + public interface IStopwatchProvider + { + /// <summary> + /// Starts a new stopwatch object. + /// </summary> + /// <returns>New stopwatch object; started at the time of the request.</returns> + IStopwatch StartStopwatch(); + } +} |