/// <summary> /// Creates poll settings from the given expiration, delay, delay multiplier and maximum delay. /// </summary> /// <param name="expiration">The expiration to use in order to know when to stop polling. Must not be null.</param> /// <param name="delay">The delay between RPC calls. Must be non-negative.</param> /// <param name="delayMultiplier">The multiplier to apply to the delay on each iteration; must be greater or equal to 1.0.</param> /// <param name="maxDelay">The maximum delay to use.</param> public PollSettings(Expiration expiration, TimeSpan delay, double delayMultiplier, TimeSpan maxDelay) { Expiration = GaxPreconditions.CheckNotNull(expiration, nameof(expiration)); Delay = GaxPreconditions.CheckNonNegativeDelay(delay, nameof(delay)); if (delayMultiplier < 1.0 || double.IsNaN(delayMultiplier)) { throw new ArgumentOutOfRangeException(nameof(delayMultiplier), delayMultiplier, "Delay multiplier must be a real number greater than or equal to 1"); } DelayMultiplier = delayMultiplier; MaxDelay = GaxPreconditions.CheckNonNegativeDelay(maxDelay, nameof(maxDelay)); }
/// <summary> /// Calculate a deadline from an <see cref="Expiration"/> and a <see cref="IClock"/>. /// </summary> /// <param name="expiration"><see cref="Expiration"/>, may be null.</param> /// <param name="clock"><see cref="IClock"/> to use for deadline calculation.</param> /// <returns>The calculated absolute deadline, or null if no deadline should be used.</returns> internal static DateTime?CalculateDeadline(this Expiration expiration, IClock clock) { GaxPreconditions.CheckNotNull(clock, nameof(clock)); if (expiration == null) { return(null); } switch (expiration.Type) { case ExpirationType.None: return(null); case ExpirationType.Timeout: return(clock.GetCurrentDateTimeUtc() + expiration.Timeout.Value); case ExpirationType.Deadline: return(expiration.Deadline.Value); default: throw new ArgumentException("Invalid expiration", nameof(expiration)); } }
/// <summary> /// Creates poll settings from the given expiration, delay and call settings. /// </summary> /// <param name="expiration">The expiration to use in order to know when to stop polling. Must not be null.</param> /// <param name="delay">The delay between RPC calls. Must be non-negative.</param> public PollSettings(Expiration expiration, TimeSpan delay) { Expiration = GaxPreconditions.CheckNotNull(expiration, nameof(expiration)); Delay = GaxPreconditions.CheckNonNegativeDelay(delay, nameof(delay)); }
/// <summary> /// Creates poll settings from the given expiration and constant delay. /// </summary> /// <param name="expiration">The expiration to use in order to know when to stop polling. Must not be null.</param> /// <param name="delay">The constant delay between RPC calls. Must be non-negative.</param> public PollSettings(Expiration expiration, TimeSpan delay) : this(expiration, delay, 1.0, delay) { }