-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTasksProgram.cs
More file actions
55 lines (46 loc) · 1.21 KB
/
Copy pathTasksProgram.cs
File metadata and controls
55 lines (46 loc) · 1.21 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
namespace Otus.AsyncAwait
{
public class TasksProgram
{
int _bufferedCount = 0;
private int _position = 0;
List<int> _buffer = new();
public Task Execute1Async()
{
if (_bufferedCount == _buffer.Count)
{
return FlushAsync();
}
return Task.CompletedTask;
}
public async Task<int> Execute2Async()
{
return await Task.FromResult(1);
}
public async Task<int> Execute3Async(int[] data)
{
if (data.Length == 0)
{
return -1;
}
return await FillBuffer(data);
}
public async ValueTask<int> Execute4Async(int[] data)
{
if (data.Length == 0)
{
return -1;
}
return await FillBuffer(data);
}
async Task FlushAsync()
{
await Task.Delay(1000);
}
async Task<int> FillBuffer(int[] data)
{
await Task.Delay(1000);
return await Task.FromResult(data.Length);
}
}
}