// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System;
namespace System.Reactive.Concurrency
{
public static partial class Scheduler
{
///
/// Returns a scheduler that represents the original scheduler, without any of its interface-based optimizations (e.g. long running scheduling).
///
/// Scheduler to disable all optimizations for.
/// Proxy to the original scheduler but without any optimizations enabled.
/// is null.
public static IScheduler DisableOptimizations(this IScheduler scheduler)
{
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
return new DisableOptimizationsScheduler(scheduler);
}
///
/// Returns a scheduler that represents the original scheduler, without the specified set of interface-based optimizations (e.g. long running scheduling).
///
/// Scheduler to disable the specified optimizations for.
/// Types of the optimization interfaces that have to be disabled.
/// Proxy to the original scheduler but without the specified optimizations enabled.
/// or is null.
public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
{
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
if (optimizationInterfaces == null)
throw new ArgumentNullException(nameof(optimizationInterfaces));
return new DisableOptimizationsScheduler(scheduler, optimizationInterfaces);
}
///
/// Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions.
///
/// Type of the exception to check for.
/// Scheduler to apply an exception filter for.
/// Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.
/// Wrapper around the original scheduler, enforcing exception handling.
/// or is null.
public static IScheduler Catch(this IScheduler scheduler, Func handler)
where TException : Exception
{
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
if (handler == null)
throw new ArgumentNullException(nameof(handler));
return new CatchScheduler(scheduler, handler);
}
}
}