Reputation: 115
I have two actors - childActor and parentActor
open System
open Akka
open Akka.FSharp
let systemActor = System.create "systemActor" <| Configuration.defaultConfig()
let childActor (mailbox: Actor<_>) =
let rec loop() = actor {
let! message = mailbox.Receive()
printfn "Message received"
return! loop()
}
loop()
let parentActor (mailbox: Actor<_>) =
let rec loop() = actor {
let! message = mailbox.Receive()
printfn "Message received"
return! loop()
}
loop()
I can create the parent actor reference using spawn function.
let parentRef = spawn systemActor "parentActor" parentActor
Now what I want to do here is to create the child actor reference under parent actor. Something like below.
let childRef = spawn parentRef "childActor" childActor
But this is not working. spawn function requires a parameter of type IActorRefFactory so it is not accepting IActorRef. Is there any way to create a child actor under parent actor in akka.net using F#?
Upvotes: 2
Views: 286
Reputation: 7542
IActorRefFactory
is an interface responsible for determining a parent and in case of Akka.FSharp it's implemented by ActorSystem
and Actor<_>
as well. So in your case just use:
let childRef = spawn mailbox "childActor" childActor
Upvotes: 4