Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created May 25, 2018 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/1d1b1807596d19ae9da368ca8a56cd1a to your computer and use it in GitHub Desktop.
Save atifaziz/1d1b1807596d19ae9da368ca8a56cd1a to your computer and use it in GitHub Desktop.
Demo of MoreLINQ's AwaitCompletion
<Query Kind="Expression">
<NuGetReference Prerelease="true">morelinq</NuGetReference>
<Namespace>MoreLinq</Namespace>
<Namespace>MoreLinq.Experimental</Namespace>
</Query>
Enumerable
.Range(1, 5)
.Select(x => TimeSpan.FromSeconds(x))
.RandomSubset(5)
.Index(1)
.Pipe(e => Console.WriteLine($"Job #{e.Key} will take {e.Value}"))
.AwaitCompletion(async (x, _) => { await Task.Delay(x.Value); return x; },
(x, t) => t.Result)
// .AsSequential()
// .AsOrdered()
// .MaxConcurrency(2)
.Pipe(e => Console.WriteLine($"Job #{e.Key} completed"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment