Created
October 17, 2017 21:32
-
-
Save mastoj/9b56f29602cbe0157afdfa97c2a64891 to your computer and use it in GitHub Desktop.
Proto.actor and F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Proto | |
open System.Threading.Tasks | |
type Message = {Text: string} | |
type Message2 = | |
| Text of string | |
module Proto = | |
let createActor<'T> f = | |
let create () = | |
{ new IActor | |
with member this.ReceiveAsync(context: IContext) = | |
let msg = context.Message | |
match msg with | |
| :? 'T as x -> f x | |
| _ -> printfn "Invalid message" | |
Actor.Done } | |
Actor.FromProducer(fun () -> create()) | |
[<EntryPoint>] | |
let main argv = | |
let handleMessage msg = | |
match msg with | |
| Text t -> printfn "This could work" | |
let props = Proto.createActor handleMessage // Actor.FromProducer(fun () -> (new MyActor() :> IActor)) | |
let pid = Actor.Spawn(props) | |
pid.Tell({Text = "Tomas"}) | |
pid.Tell(Text "Tomas") | |
System.Console.ReadLine() |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment