Проблема:
Я изо всех сил пытаюсь понять, почему мой актер Reporter не получает сообщения на основе следующего утверждения, которое находится в моем актере Generator:
reporter <! Message input
Актер моего репортера:
let reporterActor (mailbox:Actor<_>) =
let rec loop() = actor { let! msg = mailbox.Receive()
match msg |> box :?> Command with
| Start -> ()
| Message v -> printf "%s" v
| Exit -> mailbox.Context.System.Terminate() |> ignore }
loop() |> ignore
По сути, запускается консоль, которая принимает ввод от пользователя. Мой актор Generator перенаправляет этот ввод моему актору Reporter. Однако приведенный выше код никогда не выполняется.
Код следующий:
module Main
open System
open Akka.FSharp
open Akka.Actor
open Actors
type Command =
| Message of string
| Start | Exit
let reporterActor (mailbox:Actor<_>) =
let rec loop() = actor { let! msg = mailbox.Receive()
match msg |> box :?> Command with
| Start -> ()
| Message v -> printf "%s" v
| Exit -> mailbox.Context.System.Terminate() |> ignore }
loop() |> ignore
let generatorActor (reporter:IActorRef) (mailbox:Actor<_>) message =
let handle input = match input with
| "exit" -> mailbox.Context.System.Terminate |> ignore
| _ -> reporter <! Message input
handle (Console.ReadLine().ToLower())
[<EntryPoint>]
let main argv =
let system = System.create "system" (Configuration.load())
let reporterActor = spawn system "reporterActor" (actorOf(reporterActor))
let generatorActor = spawn system "generatorActor" (actorOf2(generatorActor reporterActor))
generatorActor <! Start
system.AwaitTermination ()
0
Обновление:
Я узнал, что могу активировать актор Reporter, заменив параметр почтового ящика произвольным параметром сообщения:
let reporterActor message =
match message |> box :?> Command with
| Start -> ()
| Message v -> printf "Reporting: %s" v
| Exit -> failwith "Kill this!"
Я до сих пор не понимаю, когда следует использовать параметр почтового ящика, а когда полагаться на параметр сообщения.