-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cs
60 lines (52 loc) · 2.27 KB
/
Test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class Test
{
public void ClassicMethod()
{
var sa = new SimpleAsync();
// not awaited Tasks are correctly marked when returned value is unassigned
sa.JustTask();
sa.TaskWithValue();
SimpleStaticAsync.JustTask();
SimpleStaticAsync.TaskWithValue();
// Now the same thing with assigning to variables - these are not marked - yet they are never awaited
// IMO that introduces bugs - at least in our code after changes from sync to async/await where we use var
var a = sa.JustTask();
var b = sa.TaskWithValue();
var c = SimpleStaticAsync.JustTask();
var d = SimpleStaticAsync.TaskWithValue();
Console.WriteLine(a.ToString());
Console.WriteLine(b.ToString());
Console.WriteLine(c.ToString());
Console.WriteLine(d.ToString());
// IMO these shouldn't be marked, since I want fire & forget them
_ = sa.JustTask();
_ = sa.TaskWithValue();
_ = SimpleStaticAsync.JustTask();
_ = SimpleStaticAsync.TaskWithValue();
}
public async Task AsyncMethod()
{
var sa = new SimpleAsync();
await sa.JustTask();
// not awaited Tasks are correctly marked when returned value is unassigned
sa.JustTask();
sa.TaskWithValue();
SimpleStaticAsync.JustTask();
SimpleStaticAsync.TaskWithValue();
// Now the same thing with assigning to variables - these are not marked - yet they are never awaited
// IMO that introduces bugs - at least in our code after changes from sync to async/await where we use var
var a = sa.JustTask();
var b = sa.TaskWithValue();
var c = SimpleStaticAsync.JustTask();
var d = SimpleStaticAsync.TaskWithValue();
Console.WriteLine(a.ToString());
Console.WriteLine(b.ToString());
Console.WriteLine(c.ToString());
Console.WriteLine(d.ToString());
// IMO these shouldn't be marked, since I want fire & forget them
_ = sa.JustTask();
_ = sa.TaskWithValue();
_ = SimpleStaticAsync.JustTask();
_ = SimpleStaticAsync.TaskWithValue();
}
}