What happens if Actor a calls a method on Actor b and Actor c?
Task<int> CallBAndC()
{
IActorB b = ActorProxy.Create<IActorB>(ActorId.CreateRandom(), new Uri("fabric://MyApp/MyService"));
IActorC c = ActorProxy.Create<IActorC>(ActorId.CreateRandom(), new Uri("fabric://MyApp/MyService"));
Task<int> futureBResult = b.Method();
Task<int> futureCResult = c.Method();
// do some lengthy computation
return (await futureBResult) + (await futureCResult);
}
Could 'b.Method()' and 'c.Method()' run simultaneously? Or are they run sequentially (perhaps due to being in the call context of Actor a)? What happens when 'b.Method()' and 'c.Method()' call a method of a?
It should be okay with this approach, there just a few caveats to keep in mind:
You should always await the tasks returned by an actor call, if you fire and forget you might lose the call, because there is no guarantee that the message got delivered.
When an actor send a call to another actor, it will wait in a queue util the actor is free to process the call. When the call come from same context, if Reentrancy is enabled, and the actor is waiting for an operation of same context to complete, the call will be allowed to continue.
Example: When an actor A call actor B, Then B tries to call actor A while A wait for the initial call to B to complete, The reentrancy will allow B to continue, then the result from A to B is returned, then B will return the result to A. This behaviour can be changed, when reentrant mode is disabled it will dead-lock when B tries to call A. after a timeout the operation will fail.