I'm using an actor system to calculate some data, and then I want it to return the result from not originally asked actor endpoint to my non actor oriented program. I tried using Ask or Ask<> with await or Result but it didn't help either.
This is a simplified example of what I want to achieve:
class Program
{
public static ActorSystem actorSystem;
static async Task Main(string[] args)
{
actorSystem = ActorSystem.Create("ActorSystem");
var mainActor = actorSystem.ActorOf(Props.Create(() => new MainActor()), "main");
var actorAnswer = await mainActor.Ask<object[]>(new Start(true));
//Some operations using actorAnswer from actor ...
}
}
And simplified MainActor:
class MainActor : ReceiveActor
{
public MainActor()
{
Receive<Start>(m =>
{
_commanderActor.Tell(new SomeMessage());
});
Receive<IEnumerable<int[]>>(m =>
{
if (condition)
{
Sender.Tell(new object[] {x, y});
}
else
{
_commanderActor.Tell(new SomeMessage());
}
});
}
}