aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuicommon/utils/FutureUtils.scala
blob: e8b1f5cdd73f45e438a5372a860f10e9f52cd43d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package xyz.driver.pdsuicommon.utils

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Try}

object FutureUtils {

  def executeSynchronously[T](f: ExecutionContext => Future[T]): Try[T] = {
    val future = f {
      new ExecutionContext {
        override def reportFailure(cause: Throwable): Unit = cause.printStackTrace()

        override def execute(runnable: Runnable): Unit = runnable.run()
      }
    }
    future.value.getOrElse(Failure(new IllegalStateException("Can not evaluate the result of future")))
  }
}