/// <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="seconds">The number of seconds after which to 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">seconds;Value must be greater than zero.</exception> /// <exception cref="ArgumentNullException">onTimeoutAsync</exception> public static AsyncTimeoutPolicy <TResult> TimeoutAsync <TResult>(int seconds, Func <Context, TimeSpan, Task, Task> onTimeoutAsync) { TimeoutValidator.ValidateSecondsTimeout(seconds); return(TimeoutAsync <TResult>(ctx => TimeSpan.FromSeconds(seconds), 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 cooperatively to cancellation before the policy timed it out.</remarks></param> /// <param name="timeoutStrategy">The timeout strategy.</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 <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 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, 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 cooperatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="ArgumentOutOfRangeException">timeout;Value must be greater than zero.</exception> /// <exception cref="ArgumentNullException">onTimeout</exception> public static TimeoutPolicy Timeout(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Action <Context, TimeSpan, Task, Exception> 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="seconds">The number of seconds after which to 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 cooperatively to cancellation before the policy timed it out.</remarks></param> /// <returns>The policy instance.</returns> /// <exception cref="ArgumentOutOfRangeException">seconds;Value must be greater than zero.</exception> /// <exception cref="ArgumentNullException">onTimeout</exception> public static TimeoutPolicy Timeout(int seconds, TimeoutStrategy timeoutStrategy, Action <Context, TimeSpan, Task> onTimeout) { TimeoutValidator.ValidateSecondsTimeout(seconds); return(Timeout(ctx => TimeSpan.FromSeconds(seconds), 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, 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">onTimeout</exception> public static TimeoutPolicy Timeout(TimeSpan timeout, Action <Context, TimeSpan, Task> onTimeout) { TimeoutValidator.ValidateTimeSpanTimeout(timeout); return(Timeout(ctx => timeout, TimeoutStrategy.Optimistic, onTimeout)); }