Scala: Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global

If you use a scala future, you can hit this error:

Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global

If you get this error, you can fix it by pasting this in right before the code using futures:

implicit val ec = new ExecutionContext {
  val threadPool = Executors.newFixedThreadPool(5)

  def execute(runnable: Runnable) {
    threadPool.submit(runnable)
  }

  def reportFailure(t: Throwable) {}
}