Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable tilde trigger with Akka and sbt

Tags:

scala

akka

sbt

With sbt it is possible to do ~run to recompile and run the program when the source changes. However once an ActorSystem is created it does not work anymore.

When the system is shutdown it works, but I don't want to shutdown the system.

import akka.actor.ActorSystem

object Test {
  def main(args: Array[String]) : Unit = {
    val system = ActorSystem()

    // if this line is removed, source code detection is disabled
    system.shutdown()
  }
}

Is there any workaround ?

like image 881
Pierre-Nicolas Mougel Avatar asked Nov 19 '25 16:11

Pierre-Nicolas Mougel


1 Answers

You have to remember that SBTs ~run by itself is not hot-reloading, it is simply "once the process finishes, run it again please". Akka's thread-pools are non-daemonic, which means that until the ActorSystem is "alive" the program will not terminate, thus SBT's ~run won't trigger again.

Instead you might want to look into the sbt-revolver SBT plugin, which can do what you're looking for (including for Akka based apps).

like image 85
Konrad 'ktoso' Malawski Avatar answered Nov 21 '25 10:11

Konrad 'ktoso' Malawski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!