You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got 2 Reliable actors called GameActor and PlayerActor. The ClientApp send a message to the PlayerActor when the player makes a move. Then the PlayerActor sends a message to the GameActor to indicate a movement was made. Upon being invoked, the method in the GameActor fires a notification. This notification gets handled by the ClientApp GameEventsHandler. The ClientApp then calls a method on the GameActor to retrieve the latest player positions.
ClientApp -> PlayerActor.MoveTo() -> GameActor.NotifyPlayerMoved() ->
Fire ScoreBoardUpdated event
GameEventsHandler triggered by that event ->
GameActor.GetLatestPlayerInfo()
The problem I'm having is this. The very first time I run it, the GameEventsHandler gets triggered and it tries to call the GameActor as expected. The GameActor receives the message and returns the response expected. But the client doesn't seem to receive the message. It looks like it's blocked as it doesn't throw and error or any output. Any subsequent notifications don't get handled by the event handler at all.
privatestaticasync Task RunDemo(stringgameName){varrand=new Random();
Console.WriteLine("Hit return when the service is up...");
Console.ReadLine();
Console.WriteLine("Enter your name:");varplayerName= Console.ReadLine();
Console.WriteLine("This might take a few seconds...");vargameActor= ActorProxy.Create<IGameActor>(new ActorId(gameName),new Uri(GameActorUri));await gameActor.SubscribeAsync<IGameEvents>(new GameEventsHandler(gameActor));varplayerActorId=await gameActor.JoinGameAsync(playerName, CancellationToken.None);varplayerActor= ActorProxy.Create<IPlayerActor>(new ActorId(playerActorId),new Uri(PlayerActorUri));while(true){
Console.WriteLine("Press return to move to new location...");
Console.ReadLine();await playerActor.MoveToAsync(rand.Next(100), rand.Next(100), CancellationToken.None);}}
GameEventHandler
publicvoidScoreboardUpdated(PlayerInfolastInfo){
Console.WriteLine($"Scoreboard updated. (Last move by: {lastInfo.PlayerName})");varpositions= _gameActor.GetLatestPlayerInfoAsync(CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();// this hangs foreverforeach(var playerInfo in positions)// this line never gits hit{
Console.WriteLine($"Position of {playerInfo.PlayerName} is ({playerInfo.XCoordinate},{playerInfo.YCoordinate})."+$"\nUpdated at {playerInfo.LastUpdate}\n");}}
But if I wrap the event handler logic inside a Task.Run() it seems to work.
Task.Run(async()=>{varpositions=await _gameActor.GetLatestPlayerInfoAsync(CancellationToken.None);foreach(var playerInfo in positions){ Console.WriteLine($"Position of {playerInfo.PlayerName} is ({playerInfo.XCoordinate},{playerInfo.YCoordinate})."+$"\nUpdated at {playerInfo.LastUpdate}\n");}});
AFAIK notifications aren't blocking and are not reliable. So I don't understand why my initial implementation doesn't work. The reentrant pattern doesn't apply here as per my understanding either. Can someone explain to me what's going on here? Is it expected behaviour or a bug?
The text was updated successfully, but these errors were encountered:
I've got 2 Reliable actors called
GameActor
andPlayerActor
. TheClientApp
send a message to thePlayerActor
when the player makes a move. Then thePlayerActor
sends a message to theGameActor
to indicate a movement was made. Upon being invoked, the method in theGameActor
fires a notification. This notification gets handled by theClientApp GameEventsHandler
. TheClientApp
then calls a method on theGameActor
to retrieve the latest player positions.The problem I'm having is this. The very first time I run it, the
GameEventsHandler
gets triggered and it tries to call theGameActor
as expected. TheGameActor
receives the message and returns the response expected. But the client doesn't seem to receive the message. It looks like it's blocked as it doesn't throw and error or any output. Any subsequent notifications don't get handled by the event handler at all.GameActor
PlayerActor
Client
GameEventHandler
But if I wrap the event handler logic inside a
Task.Run()
it seems to work.Full source code for the demo here https://github.com/dasiths/Service-Fabric-Reliable-Actors-Demo
AFAIK notifications aren't blocking and are not reliable. So I don't understand why my initial implementation doesn't work. The reentrant pattern doesn't apply here as per my understanding either. Can someone explain to me what's going on here? Is it expected behaviour or a bug?
The text was updated successfully, but these errors were encountered: