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

Stash not available under Scala 3 (with CrossVersion) #130

Open
devlaam opened this issue Jun 28, 2022 · 3 comments
Open

Stash not available under Scala 3 (with CrossVersion) #130

devlaam opened this issue Jun 28, 2022 · 3 comments

Comments

@devlaam
Copy link

devlaam commented Jun 28, 2022

Akka.js continues to be very useful! However, when taking my project to Scala 3 (and making use of CrossVersion.for3Use2_13) a problem with the use of Stash arises. It seems not possible to define mailbox configurations in application.conf for that file is not being read, and making use of then ConfigFactory does not work for it relies on Scala 2 macro's (not supported in Scala 3). Making an alternative Stash class is also difficult for the underlying queues in the mailboxes are not accessible (needed to get the order right).

Is there a way to somehow manually load the required mailbox class? Or do you know some other workaround?

@andreaTP
Copy link
Member

Hi @devlaam !
I have to say that I'm actually surprised that this project still works with Scala 3 🙂

There is a section on how to configure the mailbox in the main Readme:

akka.js/README.md

Lines 91 to 110 in 040fac8

***Mailbox configuration***
Due to the lack of runtime reflection in Scala.Js is not possible to configure mailbox of actors using __requirements__ but is it possible to do so with direct configuration.
i.e.
```scala
lazy val config: Config =
ConfigFactory
.parseString("""
stash-custom-mailbox {
mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
}
"""
).withFallback(akkajs.Config.default)
val system: ActorSystem = ActorSystem("wsSystem", config)
val actorWithStash =
system.actorOf(Props(new ActorWithStash()).withMailbox("stash-custom-mailbox"), "ActorWithStash")
```

I'm not sure how the macro incompatibility works in Scala 3, but if you insert a local variable in the String to parse you invalidate the Macro and everything should be resolved at runtime, but this might require more investigation.
Alternatively, you can try to use parseMap, or directly invoking the underlying implementation.

@devlaam
Copy link
Author

devlaam commented Jun 28, 2022

Hello andreaTP, thanks a lot for the quick reply!!

I already tried the way you suggested, but failed. But, since you suggested it, I thought, let's try a little harder. This is a solution i found to be working. Define your actor system with:

object SystemDef
{ import com.typesafe.config.{Config => TSConfig}
  import org.akkajs.shocon.{Config => SHConfig}
  val actSysName   = "mySystem"
  val stashMailbox = "stash-custom-mailbox"
  val stashConfig  = s""" $stashMailbox { mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox" } """
  val actorSystem  = ActorSystem(actSysName,TSConfig(SHConfig(stashConfig))) }

and make use of it like this:

object Worker 
{ case class Config(...) 
  def create(config: Config): Props = Props(new Worker(config)).withMailbox(SystemDef.stashMailbox) }

class Worker(val config: Worker.Config) extends Actor with Stash
{ ... }

Again, a big thank you (and for your wonderful work in general). Happy stashing!

@andreaTP
Copy link
Member

Thanks a lot for sharing your solution @devlaam !
And sorry if it turns out to be so ugly ...

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

2 participants