Example #1
0
        /// <summary>
        /// Read all results from feed
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="feed"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <T> > AllAsync <T>(this IResultFeed <T> feed,
                                                                 CancellationToken ct = default)
        {
            var results = new List <T>();

            while (feed.HasMore())
            {
                var result = await feed.ReadAsync(ct);

                results.AddRange(result);
            }
            return(results);
        }
        /// <summary>
        /// Invoke callback for each element
        /// </summary>
        /// <param name="feed"></param>
        /// <param name="callback"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task ForEachAsync <T>(this IResultFeed <T> feed,
                                                  Func <T, Task> callback,
                                                  CancellationToken ct = default)
        {
            while (feed.HasMore())
            {
                var results = await feed.ReadAsync(ct);

                foreach (var item in results)
                {
                    await callback(item);
                }
            }
        }