Comments (1)
Unfortunately it's only a Union type in name. I find it easiest to do this:
Declare your messages like so:
public class Msg { }
public class Add : Msg { }
public class Remove : Msg { }
public class Show : Msg { }
Then create a static Inbox
method to take a Msg
, which uses the ternary operators and pattern matching on the types to make something that looks like a match
statement in functional programming:
public static class MyActor
{
public static Unit Inbox(Msg msg) =>
msg is Add a ? Add(a)
: msg is Remove r ? Remove(r)
: msg is Show s ? Show(s)
: unit;
static Unit Add(Add msg)
{
// Use Add message
return unit;
}
static Unit Remove(Remove msg)
{
// Use Remove message
return unit;
}
static Unit Show(Show msg)
{
// Use Show message
return unit;
}
}
Because the Inbox returns Unit
and not void
, you will need to wrap it with act
when spawning:
spawn("my-actor", act<Msg, Unit>(MyActor.Inbox));
Or make the Inbox less attractive and return void
:
public static void Inbox(Msg msg)
{
var _ = msg is Add a ? Add(a)
: msg is Remove r ? Remove(r)
: msg is Show s ? Show(s)
: unit;
}
I need to update those samples, as this approach is much easier these days (with C#7).
from echo-process.
Related Issues (20)
- Probably buggy strategy ForwardToSelf / Restart HOT 6
- System.Exception: 'observe' should not be be used from within a process' message loop. HOT 7
- State diposed during inboxFn HOT 3
- null reference error when disposing system HOT 1
- How to stop an actor (restartable) HOT 2
- Message dropped when actor killed in inboxFn HOT 1
- State disposed during inboxFn when asked
- Get some notification during inboxFn when actor gets killed (CancellationToken) HOT 1
- Zombie state: Race condition on shutdown, actor state will resurrect HOT 2
- ProcessLogItem (initialise/shutdownAll timing?) HOT 2
- Current performance state compared to Akka.NET and Orleans HOT 1
- Dead lock on shutdown HOT 2
- Default value on cluster not preserved in copy HOT 1
- Master branch renamed to Main
- How to use it within an ASP.NET app?
- Wiki Process-System Docs Issues
- Wiki Error Handling Docs Issues
- Wiki Registered processes Docs Issue HOT 1
- Idea: Use Source Generators to rewrite LINQ expressions
- Issues from recent refactor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echo-process.