Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Created November 21, 2013 04:49
Show Gist options
  • Save richdougherty/7576240 to your computer and use it in GitHub Desktop.
Save richdougherty/7576240 to your computer and use it in GitHub Desktop.
implicit val system = ActorSystem("jse-system")
implicit val timeout = Timeout(5.seconds)
val engine = system.actorOf(Rhino.props(), "engine")
def tempResourceFile(resourceName: String): File = {
import org.apache.commons.io._
val url = this.getClass.getResource(resourceName);
val file = File.createTempFile(
FilenameUtils.getBaseName(resourceName),
FilenameUtils.getExtension(resourceName))
IOUtils.copy(url.openStream,
FileUtils.openOutputStream(file))
file
}
val f = tempResourceFile("/META-INF/resources/webjars/coffee-script/1.6.3/coffee-script.min.js")
val resultFuture = (engine ? Engine.ExecuteJs(f, immutable.Seq("999")))
try {
val result = Await.result(resultFuture, 5.seconds)
println(s"result: $result")
} finally {
println("Running shutdown after receiving result")
system.shutdown()
println("Waiting for termination")
system.awaitTermination()
println("Terminated")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment