/// <summary> /// 全てのレスポンスに対して指定された処理を実行します。 /// </summary> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="action">実行する処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult> ForEachAsync <TResponse>(this AsyncServerStreamingCall <TResponse> call, Action <TResponse> action) where TResponse : class { try { while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { action(call.ResponseStream.Current); } return(new GrpcResult(call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleException(call, ex)); } }
/// <summary> /// 全てのレスポンスを受信します。 /// </summary> /// <typeparam name="TResponse">レスポンスの型</typeparam> /// <typeparam name="TResult">実行結果の型</typeparam> /// <param name="call">呼び出しオブジェクト</param> /// <param name="converter">実行結果への変換処理</param> /// <returns>実行結果</returns> public static async Task <GrpcResult <IList <TResult> > > ReadAllAsync <TResponse, TResult>(this AsyncServerStreamingCall <TResponse> call, Converter <TResponse, TResult> converter) where TResponse : class { try { List <TResult> list = new List <TResult>(); while (await call.ResponseStream.MoveNext().ConfigureAwait(false)) { list.Add(converter(call.ResponseStream.Current)); } return(GrpcResult.Create <IList <TResult> >(list, call.ToInterface())); } catch (Exception ex) when(GrpcExceptionUtility.HasRpcException(ex)) { return(HandleResponseListException <TResponse, TResult>(call, ex)); } }