All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wix.async.package.scala Maven / Gradle / Ivy

There is a newer version: 0.1.10
Show newest version
package com.wix

import scala.reflect.ClassTag

/**
 * @author shaiyallin
 * @since 12/19/13
 */
package object async {
  type RetryStrategy = (Throwable => Boolean)

  val NoRetries = RetryPolicy()

  def onCheckedException(e: Throwable) = e.isInstanceOf[Exception] && !e.isInstanceOf[RuntimeException]
  def onException(e: Throwable) = e.isInstanceOf[Exception]
  def onlyOnTimeout(e: Throwable) = false
  def onAnyOf(types: Class[_ <: Throwable]*)(e: Throwable) = types.exists(_.isInstance(e))
  def on[E <: Throwable](e: Throwable)(implicit m: ClassTag[E]) = m.runtimeClass.isInstance(e)

  def onceFor[E <: Throwable](implicit m: ClassTag[E]) = RetryPolicy(retries = 1, shouldRetry = on[E])

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy