Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Core/Reactive/Concurrency/Scheduler.Wrappers.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System;
4
5 namespace System.Reactive.Concurrency
6 {
7 public static partial class Scheduler
8 {
9 /// <summary>
10 /// Returns a scheduler that represents the original scheduler, without any of its interface-based optimizations (e.g. long running scheduling).
11 /// </summary>
12 /// <param name="scheduler">Scheduler to disable all optimizations for.</param>
13 /// <returns>Proxy to the original scheduler but without any optimizations enabled.</returns>
14 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
15 public static IScheduler DisableOptimizations(this IScheduler scheduler)
16 {
17 if (scheduler == null)
18 throw new ArgumentNullException("scheduler");
19
20 return new DisableOptimizationsScheduler(scheduler);
21 }
22
23 /// <summary>
24 /// Returns a scheduler that represents the original scheduler, without the specified set of interface-based optimizations (e.g. long running scheduling).
25 /// </summary>
26 /// <param name="scheduler">Scheduler to disable the specified optimizations for.</param>
27 /// <param name="optimizationInterfaces">Types of the optimization interfaces that have to be disabled.</param>
28 /// <returns>Proxy to the original scheduler but without the specified optimizations enabled.</returns>
29 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="optimizationInterfaces"/> is null.</exception>
30 public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
31 {
32 if (scheduler == null)
33 throw new ArgumentNullException("scheduler");
34 if (optimizationInterfaces == null)
35 throw new ArgumentNullException("optimizationInterfaces");
36
37 return new DisableOptimizationsScheduler(scheduler, optimizationInterfaces);
38 }
39
40 /// <summary>
41 /// Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions.
42 /// </summary>
43 /// <typeparam name="TException">Type of the exception to check for.</typeparam>
44 /// <param name="scheduler">Scheduler to apply an exception filter for.</param>
45 /// <param name="handler">Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.</param>
46 /// <returns>Wrapper around the original scheduler, enforcing exception handling.</returns>
47 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="handler"/> is null.</exception>
48 public static IScheduler Catch<TException>(this IScheduler scheduler, Func<TException, bool> handler)
49 where TException : Exception
50 {
51 if (scheduler == null)
52 throw new ArgumentNullException("scheduler");
53 if (handler == null)
54 throw new ArgumentNullException("handler");
55
56 return new CatchScheduler<TException>(scheduler, handler);
57 }
58 }
59 }