-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (59 loc) · 2.13 KB
/
Program.cs
File metadata and controls
75 lines (59 loc) · 2.13 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
// -----------------------------------------------------------------------
// <copyright file="Program.cs" company="Asynkron AB">
// Copyright (C) 2015-2024 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Threading.Tasks;
using Proto;
internal class Program
{
private static async Task Main(string[] args)
{
var rootContext = new RootContext(new ActorSystem());
var c = 0;
var props = Props.FromFunc(context =>
{
switch (context.Message)
{
case Started _:
Console.WriteLine($"{DateTime.Now} Started");
context.SetReceiveTimeout(TimeSpan.FromSeconds(1));
break;
case ReceiveTimeout _:
c++;
Console.WriteLine($"{DateTime.Now} ReceiveTimeout: {c}");
break;
case NoInfluence _:
Console.WriteLine($"{DateTime.Now} Received a no-influence message");
break;
case string s:
Console.WriteLine($"{DateTime.Now} Received message: {s}");
break;
}
return Task.CompletedTask;
}
);
var pid = rootContext.Spawn(props);
for (var i = 0; i < 6; i++)
{
rootContext.Send(pid, "hello");
await Task.Delay(500);
}
Console.WriteLine("Hit [return] to send no-influence messages");
Console.ReadLine();
for (var i = 0; i < 6; i++)
{
rootContext.Send(pid, new NoInfluence());
await Task.Delay(500);
}
Console.WriteLine("Hit [return] to send a message to cancel the timeout");
Console.ReadLine();
rootContext.Send(pid, "cancel");
Console.WriteLine("Hit [return] to finish");
Console.ReadLine();
}
}
internal class NoInfluence : INotInfluenceReceiveTimeout
{
}