-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_CustomCombinators.cs
45 lines (36 loc) · 1.18 KB
/
06_CustomCombinators.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Threading.Tasks;
using AsyncLab.Support;
namespace AsyncLab
{
public class CustomCombinators
{
readonly IOutput output;
public CustomCombinators(IOutput output)
{
this.output = output;
}
Task<TInput> EchoAsync<TInput>(TInput input) => T.Create(output, 200, input)();
Task<TInput> EchoAsync<TInput>(TInput input, int durationInMs) => T.Create(output, durationInMs, input)();
/**
[Run]
public async Task InterleavedTasks()
{
// Build a combinator which enable to consume task in order of completion
// In this case consume == output.Log() and you should see the results
// printed in order [1, 2, 3, 4, 5]
var tasks = new[] {
EchoAsync(3, 3000),
EchoAsync(1, 1000),
EchoAsync(2, 2000),
EchoAsync(5, 5000),
EchoAsync(4, 4000),
};
await tasks.Interleaved(value =>
{
output.Log($"{value} consumed");
return value;
});
}
/**/
}
}