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

import scala.concurrent.{ExecutionContext, Future}
import scala.util.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.get
  }

}