Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka.NET Ask Task never completing

Tags:

c#

akka.net

I may be doing something incorrect, but it is not apparent. I have the following code:

 namespace test
    {
        class Program
            {
             static void Main(string[] args)

                {
                    using (var system = ActorSystem.Create("MySystem"))
                    {
                        var testPassRetriever = system.ActorOf<PrintActor>();
                        var task = testPassRetriever.Ask<PrintActorMsg>(new PrintActorMsg());

                        // prevent the application from exiting before message is handled
                        task.Wait();
                        Console.WriteLine("Finished.");
                        Console.ReadLine();
                    }
                }
        }
        class PrintActorMsg{}

        class PrintActor : ReceiveActor
        {
            public PrintActor()
            {
             Receive<PrintActorMsg>(msg => Console.WriteLine("foo"));
            }
        }
}// namespace test

The issue is that the Task returned by Ask never completes. Its status stays in the Waiting for Activation state. "Foo" does get printed on the command line so I know the actor is processing the Print message. Is there something else I am supposed to do in the overridden actor PrintMsg to mark the task completed?

like image 774
Matt Johnson Avatar asked Jun 01 '15 21:06

Matt Johnson


1 Answers

You use the ask pattern, but never send a message back. The ask task will only be completed when a message is received from the actor. The (sometimes advised) tell or fire-and-forget pattern doesn't do this.

like image 63
Martijn Avatar answered Oct 24 '22 10:10

Martijn