예제 #1
0
        static async Task <List <UserReply> > GetUsers(User.UserClient client)
        {
            List <UserReply> users = new();

            using var clientData = client.GetUsers(new UsersRequest());
            while (await clientData.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
            {
                var user = clientData.ResponseStream.Current;
                users.Add(user);
            }
            return(users);
        }
예제 #2
0
        public async Task <IEnumerable <UserReply> > GetUsersAsync()
        {
            List <UserReply> userReplies = new List <UserReply>();
            var userResult = _userClient.GetUsers(new Empty());

            try
            {
                await foreach (var user in userResult.ResponseStream.ReadAllAsync())
                {
                    userReplies.Add(user);
                }
            }
            catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
            {
                Console.WriteLine("Stream cancelled.");
            }
            return(userReplies);
        }