-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (27 loc) · 927 Bytes
/
Program.cs
File metadata and controls
32 lines (27 loc) · 927 Bytes
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
// -----------------------------------------------------------------------
// <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;
var system = new ActorSystem();
var props = Props.FromProducer(() => new HelloActor());
var pid = system.Root.Spawn(props);
system.Root.Send(pid, new Hello("ProtoActor"));
Console.ReadLine();
// Messages should be immutable to prevent race conditions between multiple actors
internal record Hello(string Who);
// This is a standard actor
internal class HelloActor : IActor
{
public Task ReceiveAsync(IContext context)
{
if (context.Message is Hello r)
{
Console.WriteLine($"Hello {r.Who}");
}
return Task.CompletedTask;
}
}