This repository was archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsynchronousChef.cs
More file actions
93 lines (79 loc) · 2.59 KB
/
AsynchronousChef.cs
File metadata and controls
93 lines (79 loc) · 2.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Threading;
using System.Threading.Tasks;
namespace CSharpAsyncExample
{
public class AsynchronousChef
{
public int DelayMultiply { get; set; }
public AsynchronousChef()
{
DelayMultiply = 100;
}
public async Task MakeBreakfast()
{
var waterTask = BoilWater();
var eggsTask = BoilEggs();
var baconTask = FryBacon();
var breadTask = ToastBread();
await breadTask;
await ApplyButter();
await ApplyJam();
await Task.WhenAll(eggsTask, baconTask, waterTask);
await PourCoffee();
await PourJuice();
}
public async Task PourCoffee()
{
Console.WriteLine("[Chef] Start pouring coffee");
await Task.Delay(5 * DelayMultiply);
Console.WriteLine("[Chef] Coffee Ready");
}
public async Task BoilEggs()
{
Console.WriteLine("[Chef] Put Eggs into boiling water");
await Task.Delay(70 * DelayMultiply);
Console.WriteLine("[Chef] Eggs Boiled");
}
public async Task FryBacon()
{
Console.WriteLine("[Chef] Throw bacon in pan");
await Task.Delay(40 * DelayMultiply);
Console.WriteLine("[Chef] Bacon Fried");
}
public async Task ToastBread()
{
Console.WriteLine("[Chef] Put bread in toaster");
await Task.Delay(20 * DelayMultiply);
Console.WriteLine("[Chef] Bread Toasted");
}
public async Task ApplyButter()
{
Console.WriteLine("[Chef] Start spreading Butter");
await Task.Delay(15 * DelayMultiply);
Console.WriteLine("[Chef] Butter applied");
}
public async Task ApplyJam()
{
Console.WriteLine("[Chef] Start spreading Jam");
await Task.Delay(15 * DelayMultiply);
Console.WriteLine("[Chef] Jam applied");
}
public async Task PourJuice()
{
Console.WriteLine("[Chef] Start pouring Juice");
await Task.Delay(5 * DelayMultiply);
Console.WriteLine("[Chef] Juice Ready");
}
public async Task BoilWater()
{
Console.WriteLine("[Chef] Set coffee water to boil");
await Task.Delay(200 * DelayMultiply);
Console.WriteLine("[Chef] Coffee Water is boiled");
}
public async Task<string> TellAJoke()
{
return "Joke";
}
}
}