示例#1
0
        /// <summary>
        /// Reads the entire stream and executes an async action for each element.
        /// </summary>
        public static async Task ForEach <T>(this IAsyncStreamReader <T> streamReader, Func <T, Task> asyncAction)
            where T : class
        {
            while (true)
            {
                var elem = await streamReader.ReadNext();

                if (elem == null)
                {
                    break;
                }
                await asyncAction(elem);
            }
        }
示例#2
0
        /// <summary>
        /// Reads the entire stream and creates a list containing all the elements read.
        /// </summary>
        public static async Task <List <T> > ToList <T>(this IAsyncStreamReader <T> streamReader)
            where T : class
        {
            var result = new List <T>();

            while (true)
            {
                var elem = await streamReader.ReadNext();

                if (elem == null)
                {
                    break;
                }
                result.Add(elem);
            }
            return(result);
        }
示例#3
0
 /// <summary>
 /// Reads the next response from ResponseStream
 /// </summary>
 /// <returns></returns>
 public Task <TResponse> ReadNext()
 {
     return(responseStream.ReadNext());
 }