Example #1
0
        public static async Task <IComicVisitPage <TResource>[]> DownloadChapterAsync <TResource>(this IComicVisiting <TResource> visiting,
                                                                                                  int index,
                                                                                                  int concurrent = 1)
        {
            if (visiting is null)
            {
                throw new ArgumentNullException(nameof(visiting));
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            var streamMgr = visiting.Host.GetRequiredService <RecyclableMemoryStreamManager>();
            var mgr       = await visiting.GetChapterManagerAsync(index);

            if (mgr == null || mgr.ChapterWithPage?.Pages == null)
            {
                return(null);
            }
            var workingTask = Enumerable.Range(0, mgr.ChapterWithPage.Pages.Length)
                              .Select(x => new Func <Task <IComicVisitPage <TResource> > >(() => mgr.GetVisitPageAsync(x)))
                              .ToArray();
            var orderMap = Enumerable.Range(0, mgr.ChapterWithPage.Pages.Length)
                           .ToDictionary(x => mgr.ChapterWithPage.Pages[x]);
            var results = await TaskQuene.RunAsync(workingTask, concurrent);

            return(results.OrderBy(x => orderMap[x.Page]).ToArray());
        }
Example #2
0
        public async Task AddSomeTaskWithValue_RuntIt_AllValueReturn()
        {
            var tasks = Enumerable.Range(0, 10)
                        .Select(x => new Func <Task <int> >(() => Task.FromResult(x)))
                        .ToArray();
            var res = await TaskQuene.RunAsync(tasks);

            Assert.AreEqual(res.Length, tasks.Length);
        }