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()); }
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); }
public async Task AddSomeTaskFunc_RunIt_AllDone() { var tasks = Enumerable.Range(0, 10) .Select(x => TaskGen(() => { })) .ToArray(); var res = await TaskQuene.RunVoidAsync(tasks); Assert.AreEqual(res.Length, tasks.Length); foreach (var item in res) { Assert.IsTrue(item.IsCompleted); } }
public static Task BatchEmitAsync(this IComicDownloader downloader, ComicDownloadRequest request, int concurrent = 5, CancellationToken token = default) { if (downloader is null) { throw new ArgumentNullException(nameof(downloader)); } if (request is null) { throw new ArgumentNullException(nameof(request)); } if (concurrent <= 0) { throw new ArgumentOutOfRangeException(nameof(concurrent)); } var tasks = downloader.EmitTasks(request, token); return(TaskQuene.RunVoidAsync(tasks, concurrent)); }