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.Core/Reactive/Concurrency/Scheduler.Wrappers.cs | |
parent | d90a52595e24b1216c89f6cb5f245262db1810ae (diff) |
partial import of ca05fdeb565e: Reactive Extensions OSS V1.0
Diffstat (limited to 'Rx.NET/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs')
-rw-r--r-- | Rx.NET/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Rx.NET/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs b/Rx.NET/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs new file mode 100644 index 0000000..a30ff69 --- /dev/null +++ b/Rx.NET/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs @@ -0,0 +1,59 @@ +// 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 +{ + public static partial class Scheduler + { + /// <summary> + /// Returns a scheduler that represents the original scheduler, without any of its interface-based optimizations (e.g. long running scheduling). + /// </summary> + /// <param name="scheduler">Scheduler to disable all optimizations for.</param> + /// <returns>Proxy to the original scheduler but without any optimizations enabled.</returns> + /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception> + public static IScheduler DisableOptimizations(this IScheduler scheduler) + { + if (scheduler == null) + throw new ArgumentNullException("scheduler"); + + return new DisableOptimizationsScheduler(scheduler); + } + + /// <summary> + /// Returns a scheduler that represents the original scheduler, without the specified set of interface-based optimizations (e.g. long running scheduling). + /// </summary> + /// <param name="scheduler">Scheduler to disable the specified optimizations for.</param> + /// <param name="optimizationInterfaces">Types of the optimization interfaces that have to be disabled.</param> + /// <returns>Proxy to the original scheduler but without the specified optimizations enabled.</returns> + /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="optimizationInterfaces"/> is null.</exception> + public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces) + { + if (scheduler == null) + throw new ArgumentNullException("scheduler"); + if (optimizationInterfaces == null) + throw new ArgumentNullException("optimizationInterfaces"); + + return new DisableOptimizationsScheduler(scheduler, optimizationInterfaces); + } + + /// <summary> + /// Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions. + /// </summary> + /// <typeparam name="TException">Type of the exception to check for.</typeparam> + /// <param name="scheduler">Scheduler to apply an exception filter for.</param> + /// <param name="handler">Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.</param> + /// <returns>Wrapper around the original scheduler, enforcing exception handling.</returns> + /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="handler"/> is null.</exception> + public static IScheduler Catch<TException>(this IScheduler scheduler, Func<TException, bool> handler) + where TException : Exception + { + if (scheduler == null) + throw new ArgumentNullException("scheduler"); + if (handler == null) + throw new ArgumentNullException("handler"); + + return new CatchScheduler<TException>(scheduler, handler); + } + } +} |