/// <summary> /// Creates and initializes a retryable read operation context. /// </summary> /// <param name="binding">The binding.</param> /// <param name="retryRequested">if set to <c>true</c> [retry requested].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A retryable read context.</returns> public static async Task <RetryableReadContext> CreateAsync(IReadBinding binding, bool retryRequested, CancellationToken cancellationToken) { var context = new RetryableReadContext(binding, retryRequested); try { await context.InitializeAsync(cancellationToken).ConfigureAwait(false); if (ChannelPinningHelper.PinChannelSourceAndChannelIfRequired( context.ChannelSource, context.Channel, context.Binding.Session, out var pinnedChannelSource, out var pinnedChannel)) { context.ReplaceChannelSource(pinnedChannelSource); context.ReplaceChannel(pinnedChannel); } return(context); } catch { context.Dispose(); throw; } }
/// <summary> /// Creates and initializes a retryable read operation context. /// </summary> /// <param name="binding">The binding.</param> /// <param name="retryRequested">if set to <c>true</c> [retry requested].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A retryable read context.</returns> public static async Task <RetryableReadContext> CreateAsync(IReadBinding binding, bool retryRequested, CancellationToken cancellationToken) { var context = new RetryableReadContext(binding, retryRequested); try { await context.InitializeAsync(cancellationToken).ConfigureAwait(false); return(context); } catch { context.Dispose(); throw; } }