Comments (3)
Just use nested match like here
P.S. Generic actor grains were deprecated since 2.x exactly due to this reason (we canβt have DU with system messages). DU are only for public interface, ie caller side type safety.
from orleankka.
Ok, maybe I should write something like
type GrainMessage<'t> = | Msg of 't | Timer of Timer | ..
type TypedGrain<'t> () =
inherit ActorGrain()
abstract member this.TypedReceive ( msg: GrainMessage<'t>)
override this.Receive (message) =
match message with
| :? 't as msg -> this.TypedReceive(GrainMessage(msg))
| :? Timer as msg -> this.TypedReceive(GrainMessage ( msg))
.. etc
and then use it like ActorGrain
but with TypedReceive
method instead of Receive
.
π€
from orleankka.
I've created this
type ActorMsg<'t> =
| Msg of 't
| Timer of Orleankka.Timer
| Reminder of Orleankka.Reminder
| Activate of Orleankka.Activate
| Deactivate of Orleankka.Deactivate
[<AbstractClass>]
type TypedActor<'a>() =
inherit ActorGrain()
abstract member ReceiveT: ActorMsg<'a> -> System.Threading.Tasks.Task<obj>
override this.Receive(msg:obj) = task {
match msg with
| :? 'a as m -> return! this.ReceiveT (Msg m)
| :? Orleankka.Timer as t -> return! this.ReceiveT( Timer t)
| :? Orleankka.Activate as a -> return! this.ReceiveT ( Activate a)
| :? Orleankka.Deactivate as d -> return! this.ReceiveT( Deactivate d)
| _ -> return unhandled() }
and use it like
type HelloGrain (loggerFactory:ILoggerFactory) =
inherit TypedActor<HelloMessages>()
let log = loggerFactory.CreateLogger(typeof<HelloGrain>)
interface IHello
override this.ReceiveT(msg) = task {
match msg with
| Msg(Hi)->
log.LogInformation("Client asked to say Hi!")
return some "Oh, hi!"
| Msg(Hello s) ->
log.LogInformation (sprintf "Client asked to say Hello to %s" s)
return sprintf "Hello, %s" s |> some
| Msg(Bue) ->
log.LogInformation ("Client wants to go")
return none()
| _ -> return unhandled()
}
and it's awesome!
from orleankka.
Related Issues (20)
- Document F# bugger or add a startup check HOT 1
- Create template for dotnet cli tool HOT 4
- Orleans AlwaysInterleave question HOT 3
- Missing ServiceId of ClusterOptions in F# samples and Docs HOT 1
- Storage provider issue HOT 1
- Orleankka + Dashboard \n Dashboard can't see methods information
- What should I do to call orleankka actor from orleans silo? HOT 5
- Is ImplicitStreamSubscription supported? HOT 5
- .Net Core 3 Preview 6 Idiomatic Example HOT 4
- Auto.Interfaces assembly generated in wrong folder HOT 4
- Undefined UseOrleankka HOT 1
- Is this project active? HOT 4
- Feature request: StreamRefMiddleware HOT 3
- Allow IActorGrain and GrainWithStringKey in inherited interface
- Nake.bat uses version of EventStore no longer available
- Missing NuGet for Orleankka.TestKit version 7.0.0 HOT 2
- ActorPath changes between ActorRef and ActorGrain HOT 4
- StreamRef and ImplicitStreamSubscription issues HOT 2
- Impact of Orleans 7.0 Stream Changes to Memory Stream / SMS
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 orleankka.