/// <summary> /// Builds a <see cref="Policy{TResult}" /> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> public static TimeoutPolicy <TResult> Timeout <TResult>(TimeSpan timeout, TimeoutStrategy timeoutStrategy) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); Action <Context, TimeSpan, Task, Exception> doNothing = (_, __, ___, ____) => { }; return(Timeout <TResult>(ctx => timeout, timeoutStrategy, doNothing)); }
/// <summary> /// Builds a <see cref="Policy" /> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> public static TimeoutPolicy TimeoutAsync(TimeSpan timeout, TimeoutStrategy timeoutStrategy) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); Func <Context, TimeSpan, Task, Exception, Task> doNothingAsync = (_, __, ___, ____) => TaskHelper.EmptyTask; return(TimeoutAsync(ctx => timeout, timeoutStrategy, doNothingAsync)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> public static TimeoutPolicy Timeout(TimeSpan timeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); Action <Context, TimeSpan, Task, Exception> doNothing = (_, __, ___, ____) => { }; return(Timeout(ctx => timeout, TimeoutStrategy.Optimistic, doNothing)); }
/// <summary> /// Builds an <see cref="AsyncPolicy{TResult}"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> public static AsyncTimeoutPolicy <TResult> TimeoutAsync <TResult>(TimeSpan timeout, TimeoutStrategy timeoutStrategy) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); Func <Context, TimeSpan, Task, Exception, Task> doNothingAsync = (_, __, ___, ____) => Task.FromResult(default(TResult)); return(TimeoutAsync <TResult>(ctx => timeout, timeoutStrategy, doNothingAsync)); }
/// <summary> /// Builds a <see cref="Policy{TResult}"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> public static TimeoutPolicy <TResult> TimeoutAsync <TResult>(TimeSpan timeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); Func <Context, TimeSpan, Task, Task> doNothingAsync = (_, __, ___) => TaskHelper.FromResult(default(TResult)); return(TimeoutAsync <TResult>(ctx => timeout, TimeoutStrategy.Optimistic, doNothingAsync)); }
/// <summary> /// Builds an <see cref="AsyncPolicy{TResult}"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="onTimeoutAsync">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref="Task"/> capturing the abandoned, timed-out action. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> /// <exception cref="System.ArgumentNullException">onTimeoutAsync</exception> public static AsyncTimeoutPolicy <TResult> TimeoutAsync <TResult>(TimeSpan timeout, Func <Context, TimeSpan, Task, Task> onTimeoutAsync) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); if (onTimeoutAsync == null) { throw new ArgumentNullException(nameof(onTimeoutAsync)); } return(TimeoutAsync <TResult>(ctx => timeout, TimeoutStrategy.Optimistic, onTimeoutAsync)); }
/// <summary> /// Builds an <see cref="AsyncPolicy{TResult}"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="onTimeoutAsync">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref="Task"/> capturing the abandoned, timed-out action. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> /// <exception cref="System.ArgumentNullException">onTimeoutAsync</exception> public static AsyncTimeoutPolicy <TResult> TimeoutAsync <TResult>(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Func <Context, TimeSpan, Task, Task> onTimeoutAsync) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(TimeoutAsync <TResult>(ctx => timeout, timeoutStrategy, onTimeoutAsync)); }
/// <summary> /// Builds a <see cref="Policy" /> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <param name="onTimeoutAsync">An action to call on timeout, passing the execution context, the timeout applied, the <see cref="Task" /> capturing the abandoned, timed-out action, and the captured <see cref="Exception"/>. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be greater than zero.</exception> /// <exception cref="System.ArgumentNullException">onTimeoutAsync</exception> public static TimeoutPolicy TimeoutAsync(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Func <Context, TimeSpan, Task, Exception, Task> onTimeoutAsync) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(TimeoutAsync(ctx => timeout, timeoutStrategy, onTimeoutAsync)); }
/// <summary> /// Builds an <see cref="AsyncPolicy"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="onTimeoutAsync">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref="Task"/> capturing the abandoned, timed-out action. /// <remarks>The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> /// <exception cref="ArgumentNullException">onTimeoutAsync</exception> public static AsyncTimeoutPolicy TimeoutAsync(TimeSpan timeout, Func <Context, TimeSpan, Task, Task> onTimeoutAsync) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(TimeoutAsync(ctx => timeout, TimeoutStrategy.Optimistic, onTimeoutAsync)); }
/// <summary> /// Builds a <see cref="Policy{TResult}" /> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <typeparam name="TResult">The return type of delegates which may be executed through the policy.</typeparam> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <param name="onTimeout">An action to call on timeout, passing the execution context, the timeout applied, the <see cref="Task{TResult}" /> capturing the abandoned, timed-out action, and the captured <see cref="Exception"/>. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be greater than zero.</exception> /// <exception cref="System.ArgumentNullException">onTimeout</exception> public static TimeoutPolicy <TResult> Timeout <TResult>(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Action <Context, TimeSpan, Task, Exception> onTimeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(Timeout <TResult>(ctx => timeout, timeoutStrategy, onTimeout)); }
/// <summary> /// Builds a <see cref="Policy{TResult}"/> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="onTimeout">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref="Task{TResult}"/> capturing the abandoned, timed-out action. /// <remarks>The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> /// <exception cref="ArgumentNullException">onTimeout</exception> public static TimeoutPolicy <TResult> Timeout <TResult>(TimeSpan timeout, Action <Context, TimeSpan, Task> onTimeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(Timeout <TResult>(_ => timeout, TimeoutStrategy.Optimistic, onTimeout)); }
/// <summary> /// Builds a <see cref="Policy" /> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="timeoutStrategy">The timeout strategy.</param> /// <param name="onTimeout">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref="Task" /> capturing the abandoned, timed-out action. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout)</exception> /// <exception cref="System.ArgumentNullException">onTimeout</exception> public static TimeoutPolicy Timeout(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Action <Context, TimeSpan, Task> onTimeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(Timeout(ctx => timeout, timeoutStrategy, onTimeout)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout. /// </summary> /// <param name="timeout">The timeout.</param> /// <param name="onTimeout">An action to call on timeout, passing the execution context, the timeout applied, the <see cref="Task"/> capturing the abandoned, timed-out action, and captured <see cref="Exception"/>. /// <remarks>The Task parameter will be null if the executed action responded co-operatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">timeout;Value must be greater than zero.</exception> /// <exception cref="System.ArgumentNullException">onTimeout</exception> public static TimeoutPolicy Timeout(TimeSpan timeout, Action <Context, TimeSpan, Task, Exception> onTimeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(Timeout(ctx => timeout, TimeoutStrategy.Optimistic, onTimeout)); }