com.gilt.gfc.concurrent

FutureBuilder

case class FutureBuilder[A, R] extends Product with Serializable

A convenience wrapper around Future-based calls.

Typically we have an API that returns some Future[OpResult] and we need to set an operation timeout, possibly provide a default value, possibly log how long it took for debugging, maybe retry.

By default it builds a Future[Try[A]] from Future[A]. When default value is provided it builds Future[A] from Future[A]. At the very minimum it'll apply a mandatory timeout but you can add retry logic, call tracer, etc.

It is important to specify type A _at_the_time_of_creation_, type inference doesn't pick it up.

FutureBuilder[Option[Foo]]("FooCall")......

We want to apply timeouts to *all* Futures, so,

...futureBuilder.runWithTimeout(100 milliseconds){ .... something that returns Future ... }
Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. FutureBuilder
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. val addNumRetries: (⇒ Future[Try[A]]) ⇒ Future[Try[A]]

  7. val addSingleCallTimeout: (⇒ Future[Try[A]]) ⇒ Future[Try[A]]

  8. val addTraceCalls: (⇒ Future[Try[A]]) ⇒ Future[Try[A]]

  9. val additionalMessage: String

  10. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  11. val callName: String

  12. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  14. val errorHandler: (⇒ Future[Try[A]]) ⇒ Future[R]

  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  17. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  18. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  21. val passThroughExceptionHandler: PartialFunction[Throwable, Throwable]

  22. def retry(n: Int)(implicit ec: ExecutionContext): FutureBuilder[A, R]

    Will retry this many times before giving up and returning an error.

  23. def runWithTimeout(after: FiniteDuration, errorMessage: Option[String])(call: ⇒ Future[A]): Future[R]

    Composes all the Future transformations, gives resulting Future back.

    Composes all the Future transformations, gives resulting Future back. This is the only 'run' function here, so, effectively we insist on timeouts for all futures.

    By default NonFatal failures are caught and represented as a Try[A]. OTOH if a serviceErrorDefaultValue is provided than we log errors and default to that, result type remains A.

    after

    mandatory timeout we set on 'service call' Futures

    errorMessage

    Error message that will be used to construct any resultant TimeoutException

    call

    'by name' parameter that evaluates to a Future[SomeServiceCallResult], this may be called multiple times if retry() is enabled.

    returns

    Future[SomeServiceCallResult] if a default value is provided or Future[Try[SomeServiceCallResult]] in case there's no default, a 'checked exception' of sorts.

  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  25. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def withPassThroughExceptions(handlePassThroughExceptions: PartialFunction[Throwable, Throwable]): FutureBuilder[A, R]

    Unfortunately, some exceptions are 'data' and are important for control flow, in their unmodified/unwrapped form, this allows caller to enumerate them and even (optionally) transform to another exception type.

    Unfortunately, some exceptions are 'data' and are important for control flow, in their unmodified/unwrapped form, this allows caller to enumerate them and even (optionally) transform to another exception type.

    When we get one of these we don't want to retry() service calls, we don't want to wrap them with additional user message, we just want to pass them through.

  29. def withServiceErrorDefaultValue(v: A): FutureBuilder[A, A]

    Will return this value if a call fails or we fail to interpret results.

  30. def withTraceCalls(callTracer: (FutureTrace) ⇒ Unit): FutureBuilder[A, R]

    Enables call tracing via provided callback function.

    Enables call tracing via provided callback function. E.g. you can log call times or send metrics somewhere.

    callTracer

    will be called with the results of a call.

Deprecated Value Members

  1. def runWithTimeout(after: FiniteDuration)(call: ⇒ Future[A]): Future[R]

    Composes all the Future transformations, gives resulting Future back.

    Composes all the Future transformations, gives resulting Future back. This is the only 'run' function here, so, effectively we insist on timeouts for all futures.

    By default NonFatal failures are caught and represented as a Try[A]. OTOH if a serviceErrorDefaultValue is provided than we log errors and default to that, result type remains A.

    after

    mandatory timeout we set on 'service call' Futures

    call

    'by name' parameter that evaluates to a Future[SomeServiceCallResult], this may be called multiple times if retry() is enabled.

    returns

    Future[SomeServiceCallResult] if a default value is provided or Future[Try[SomeServiceCallResult]] in case there's no default, a 'checked exception' of sorts.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.2.0) Use runWithTimeout(FiniteDuration, Option[String]) instead

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped