This repository was archived by the owner on Aug 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_TaskComposition.cs
More file actions
62 lines (53 loc) · 1.66 KB
/
03_TaskComposition.cs
File metadata and controls
62 lines (53 loc) · 1.66 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using AsyncLab.Support;
namespace AsyncLab
{
/**
* Use EchoAsync(value) to invoke an async function that return the same value back
* Use output.Log(object|string) to pretty print results onto the console
*/
//[DoNotRun]
public class TaskComposition
{
readonly IOutput 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)();
public TaskComposition(IOutput output)
{
this.output = output;
}
/**
[Run]
public void Sequential()
{
// Run EchoAsync("1") then EchoAsync("2") (sequentially) and print the results
}
/**
[Run]
public void Parallel()
{
// Run EchoAsync("1"), EchoAsync("2") in parallel and print the results
}
/**
[Run]
public void Mixed()
{
// Run Echo("1"), Echo("2") then Echo("3") then Echo("4"), Echo("5") then print the results
}
[Run]
public async Task Mixed2()
{
// Run [Echo("1") then Echo(echo1 + "+2")]
// [Echo("3") then Echo(echo3 + "+4")]
// then Echo(1+2+3+4+"5")
//
// If you keep concatenating the string you should see "1+2+3+4+5"
}
/**/
}
}