-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
34 lines (27 loc) · 851 Bytes
/
Program.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
using System.Runtime.CompilerServices;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", (CancellationToken token) => new FooClass { Stream1 = DoWork(token), Stream2 = DoWork(token) });
app.Run();
static async IAsyncEnumerable<int> DoWork([EnumeratorCancellation] CancellationToken token)
{
for (int i = 0; i < 30; i++)
{
yield return i;
await Task.Delay(100, token);
}
SimulateSporadicFailure();
void SimulateSporadicFailure()
{
if (DateTimeOffset.UtcNow.Second > 30)
throw new Exception();
}
}
class FooClass
{
public string Before => "start";
public IAsyncEnumerable<int> Stream1 { get; init; }
public string Between => "middle";
public IAsyncEnumerable<int> Stream2 { get; init; }
public string After => "end";
}