| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Threading; |
| | | 6 | | using dotnet_etcd.interfaces; |
| | | 7 | | using Grpc.Core; |
| | | 8 | | |
| | | 9 | | namespace dotnet_etcd; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Factory for creating async streaming calls to etcd |
| | | 13 | | /// </summary> |
| | | 14 | | /// <typeparam name="TRequest">The request type</typeparam> |
| | | 15 | | /// <typeparam name="TResponse">The response type</typeparam> |
| | | 16 | | public class AsyncStreamCallFactory<TRequest, TResponse> : IAsyncStreamCallFactory<TRequest, TResponse> |
| | | 17 | | { |
| | | 18 | | private readonly Func<Metadata, DateTime?, CancellationToken, AsyncDuplexStreamingCall<TRequest, TResponse>> |
| | | 19 | | _callFactory; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="AsyncStreamCallFactory{TRequest, TResponse}" /> class. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="callFactory">Factory function to create the gRPC call</param> |
| | | 25 | | /// <exception cref="ArgumentNullException">Thrown if callFactory is null</exception> |
| | 63 | 26 | | public AsyncStreamCallFactory( |
| | 63 | 27 | | Func<Metadata, DateTime?, CancellationToken, AsyncDuplexStreamingCall<TRequest, TResponse>> callFactory) => |
| | 63 | 28 | | _callFactory = callFactory ?? throw new ArgumentNullException(nameof(callFactory)); |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public IAsyncDuplexStreamingCall<TRequest, TResponse> CreateDuplexStreamingCall( |
| | | 32 | | Metadata headers, |
| | | 33 | | DateTime? deadline, |
| | | 34 | | CancellationToken cancellationToken) |
| | 0 | 35 | | { |
| | 0 | 36 | | AsyncDuplexStreamingCall<TRequest, TResponse> call = _callFactory(headers, deadline, cancellationToken); |
| | 0 | 37 | | return new AsyncDuplexStreamingCallAdapter<TRequest, TResponse>(call); |
| | 0 | 38 | | } |
| | | 39 | | } |