Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open Akka.FSharp
- type PersonName = PersonName of string
- type Person = {Name:PersonName; Age:int}
- type ActorMessage =
- | BeginProcess of PersonName
- | PersonDetails of Person
- [<EntryPoint>]
- let main argv =
- let system = System.create "my-system" (Configuration.defaultConfig())
- let detailsActor =
- spawn system "my-child-actor" <| actorOf2
- (fun mailbox name ->
- // ... Normally we have some query here for the user ...
- // But we are just going to Tell the sender actor about a Person
- mailbox.Sender() <! (PersonDetails {Name=name; Age=99}) )
- let rootActor =
- spawn system "my-parent-actor"
- <| fun mailbox ->
- let rec idle () =
- actor {
- let! message = mailbox.Receive()
- match message with
- | BeginProcess name ->
- detailsActor <! name
- return! awaitingdetails name
- | _ ->
- return! idle ()
- }
- and awaitingdetails name =
- actor {
- let! message = mailbox.Receive()
- match message with
- | PersonDetails person ->
- printfn "Received person :: %A" person
- mailbox.UnstashAll()
- return! idle ()
- | _ ->
- mailbox.Stash()
- return! awaitingdetails name
- }
- idle ()
Add Comment
Please, Sign In to add comment