Created
June 25, 2019 14:51
-
-
Save padurean/888007d72e2cd554e2cdb52178b890c2 to your computer and use it in GitHub Desktop.
Execute JavaScript dynamically in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(args: Array[String]): Unit = { | |
import javax.script.ScriptEngineManager | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val engine = new ScriptEngineManager().getEngineByMimeType("text/javascript") | |
// val script = "-1000 * %d" format 3 | |
val endless = "(function foo() { foo(); })()" | |
val result = Await.result(Future(engine.eval(endless)), 3.millis) | |
println(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment