Skip to content

Instantly share code, notes, and snippets.

@mastoj
Created October 17, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastoj/9b56f29602cbe0157afdfa97c2a64891 to your computer and use it in GitHub Desktop.
Save mastoj/9b56f29602cbe0157afdfa97c2a64891 to your computer and use it in GitHub Desktop.
Proto.actor and F#
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