Class/Object

com.gilt.gfc.concurrent

FutureBuilder

Related Docs: object FutureBuilder | package concurrent

Permalink

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
Visibility
  1. Public
  2. All

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. val addNumRetries: (FutureBuilder[_, _]) ⇒ (⇒ Future[Try[A]]) ⇒ Future[Try[A]]

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

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

    Permalink
  7. val additionalMessage: String

    Permalink
  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. val callName: String

    Permalink
  10. def clone(): AnyRef

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

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

    Permalink
  13. def finalize(): Unit

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

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

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

    Permalink
    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

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

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

    Permalink

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

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

    Permalink

    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.

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

    Permalink
    Definition Classes
    AnyRef
  23. final def wait(): Unit

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

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

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

    Permalink

    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.

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

    Permalink

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

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

    Permalink

    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.

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped