Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing zio actor references between Scala objects #482

Open
Raff97 opened this issue Jan 30, 2023 · 0 comments
Open

Passing zio actor references between Scala objects #482

Raff97 opened this issue Jan 30, 2023 · 0 comments

Comments

@Raff97
Copy link

Raff97 commented Jan 30, 2023

Hi,
I am wondering if it is possible to instantiate inside an object in Scala (called for example FirstObject) a zio actor, and then be able to pass the reference of this actor into another Scala object (called for example SecondObject), and to call in SecondObject the ask method (?) on the actor reference , so as to send messages to the actor.

I have this doubt because I have done some trials, but only if I send messages to the actor via the ask method in the object in which the actor is created (FirstObject), do I get a response from the actor, otherwise if I call the ask method in SecondObject, the application remains blocked waiting for the response of the actor (without ever receiving it).

I tried in FirstObject to save the actor reference in the variable reference


  val myAppLogic = for {
    system <- ActorSystem("mySystem")
    MyActorReference <- system.make("MyActor ", Supervisor.none, (), stateful)
  } yield (reference = MyActorReference )

and then pass this variable inside SecondObject, so as to insert it in the zio effect:

 val myAppLogic = for {
   response<- reference ? MyCommand(SomeCommand)
   _   <- printLine("The response is:  ",response)
  } yield ()

Could someone help me figure out what is wrong with my code, or in general if it is possible to implement this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant