Easily execute Scala Futures with metrics
Create a Future Executor, specifying the number of threads
val futureExecutor = FutureExecutor(4)Execute some async code and get a future back
val futureInt: Future[Int] = futureExecutor future {
val result = 1234 //Some complex operation
result
}Map the results of a future
val futureString: Future[String] = futureExecutor.map(futureInt) { value =>
value.toString
}Get the execution metrics
val stats: FutureExecutorStats = futureExecutor.statsSee the "SampleApp" for more examples (or run ./SampleApp.sh)
By default, a Fork-Join Thread Pool is used
val futureExecutor = FutureExecutor(4)and
val futureExecutor = ForkJoinFutureExecutor(4)are equivalent.
A Fixed Thread Pool can also be used
val futureExecutor = FixedFutureExecutor(4)The flexible execution models are accomplished via mixins and can be worked with directly
val futureExecutor = new FutureExecutor with FixedThreadPool {
override val numberOfThreads = 100
}This project is built with Maven. SBT support will be added in a future release.
mvn clean install