Beispiel #1
0
        public static async Task <T[]> GetRangeAsync <T>(this BlockSlots <T> blockSlots, int from, int?to)
            where T : class
        {
            if (blockSlots is null)
            {
                throw new ArgumentNullException(nameof(blockSlots));
            }
            if (from < 0 || to < 0 || to > blockSlots.Size || from > blockSlots.Size || from > to || blockSlots.Size == 0)
            {
                throw new ArgumentOutOfRangeException($"to must less {blockSlots.Size}");
            }
            var t = to ?? (blockSlots.Size - 1);

            if (from >= t)
            {
#if NET461 || NETSTANDARD2_0
                return(Array.Empty <T>());
#else
                return(new T[0]);
#endif
            }
            var rets = new T[t - from + 1];
            for (int i = from; i <= t; i++)
            {
                rets[i] = await blockSlots.GetAsync(i);
            }
            return(rets);
        }
Beispiel #2
0
        public static IEnumerable <Func <Task <T> > > ToLoadEnumerable <T>(this BlockSlots <T> blockSlots, int start = 0, int?end = null)
            where T : class
        {
            if (blockSlots is null)
            {
                throw new ArgumentNullException(nameof(blockSlots));
            }
            if (start < 0 || end > blockSlots.Size || end < 0 || start > blockSlots.Size || start > end || blockSlots.Size == 0)
            {
                throw new ArgumentOutOfRangeException($"Must [{0},{blockSlots.Size}]");
            }
            while (start < blockSlots.Size && (end == null || start < end))
            {
                var i = start;
                yield return(() => blockSlots.GetAsync(i));

                start++;
            }
        }
Beispiel #3
0
 protected override Task <TValue> LoadAsync(int index)
 {
     return(blockSlots.GetAsync(index));
 }