Packages

o

scala.compat.java8

FutureConverters

object FutureConverters

This class contains static methods which convert between Java CompletionStage and Scala Future. This is useful when mediating between Scala and Java libraries with asynchronous APIs.

Note that the bridge is implemented at the read-only side of asynchronous handles, namely scala.concurrent.Future instead of scala.concurrent.Promise and CompletionStage instead of CompletableFuture. This is intentional, as the semantics of bridging the write-handles would be prone to race conditions; if both ends (CompletableFuture and Promise) are completed independently at the same time, they may contain different values afterwards. For this reason, toCompletableFuture() is not supported on the created CompletionStages.

Example usage:

import java.util.concurrent.CompletionStage;
import scala.concurrent.Future;
import static scala.concurrent.java8.FutureConverters.*;

final CompletionStage<String> cs = ... // from an async Java API
final Future<String> f = toScala(cs);
...
final Future<Integer> f2 = ... // from an async Scala API
final CompletionStage<Integer> cs2 = toJava(f2);
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FutureConverters
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class CompletionStageOps[T] extends AnyVal
  2. final class FutureOps[T] extends AnyVal

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. implicit def CompletionStageOps[T](cs: CompletionStage[T]): CompletionStageOps[T]
  5. implicit def FutureOps[T](f: Future[T]): FutureOps[T]
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def failedPromise[T](ex: Throwable): Promise[T]

    Construct an already fulfilled scala.concurrent.Promise which holds the given failure.

    Construct an already fulfilled scala.concurrent.Promise which holds the given failure.

    returns

    the fulfilled Promise

  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  12. def fromExecutor(e: Executor): ExecutionContextExecutor

    Creates an ExecutionContext from a given Executor, using the default reporter for uncaught exceptions which will just call .printStackTrace().

    Creates an ExecutionContext from a given Executor, using the default reporter for uncaught exceptions which will just call .printStackTrace().

    e

    an Executor

    returns

    an ExecutionContext backed by the given Executor

  13. def fromExecutor(e: Executor, reporter: Consumer[Throwable]): ExecutionContextExecutor

    Creates an ExecutionContext from a given Executor, using the given Consumer for reporting errors.

    Creates an ExecutionContext from a given Executor, using the given Consumer for reporting errors. The latter can be created as in the following example:

    final ExecutionContext ec = Converter.fromExecutor(es, thr -> thr.printStackTrace());
    e

    an Executor

    reporter

    a Consumer for reporting errors during execution

    returns

    an ExecutionContext backed by the given Executor

  14. def fromExecutorService(e: ExecutorService): ExecutionContextExecutorService

    Creates an ExecutionContext from a given ExecutorService, using the default reporter for uncaught exceptions which will just call .printStackTrace().

    Creates an ExecutionContext from a given ExecutorService, using the default reporter for uncaught exceptions which will just call .printStackTrace().

    e

    an ExecutorService

    returns

    an ExecutionContext backed by the given ExecutorService

  15. def fromExecutorService(e: ExecutorService, reporter: Consumer[Throwable]): ExecutionContextExecutorService

    Creates an ExecutionContext from a given ExecutorService, using the given Consumer for reporting errors.

    Creates an ExecutionContext from a given ExecutorService, using the given Consumer for reporting errors. The latter can be created as in the following example:

    final ExecutionContext ec = Converter.fromExecutorService(es, thr -> thr.printStackTrace());
    e

    an ExecutorService

    reporter

    a Consumer for reporting errors during execution

    returns

    an ExecutionContext backed by the given ExecutorService

  16. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def globalExecutionContext: ExecutionContext

    Return the global ExecutionContext for Scala Futures.

    Return the global ExecutionContext for Scala Futures.

    returns

    the ExecutionContext

  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def keptPromise[T](v: T): Promise[T]

    Construct an already fulfilled scala.concurrent.Promise which holds the given value.

    Construct an already fulfilled scala.concurrent.Promise which holds the given value.

    returns

    the fulfilled Promise

  21. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. def promise[T](): Promise[T]

    Construct an empty scala.concurrent.Promise.

    Construct an empty scala.concurrent.Promise.

    returns

    a Promise which is not yet completed

  25. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  26. def toJava[T](f: Future[T]): CompletionStage[T]

    Returns a CompletionStage that will be completed with the same value or exception as the given Scala Future when that completes.

    Returns a CompletionStage that will be completed with the same value or exception as the given Scala Future when that completes. Since the Future is a read-only representation, this CompletionStage does not support the toCompletableFuture method. The semantics of Scala Future demand that all callbacks are invoked asynchronously by default, therefore the returned CompletionStage routes all calls to synchronous transformations to their asynchronous counterparts, i.e. thenRun will internally call thenRunAsync.

    f

    The Scala Future which may eventually supply the completion for the returned CompletionStage

    returns

    a CompletionStage that runs all callbacks asynchronously and does not support the CompletableFuture interface

  27. def toScala[T](cs: CompletionStage[T]): Future[T]

    Returns a Scala Future that will be completed with the same value or exception as the given CompletionStage when that completes.

    Returns a Scala Future that will be completed with the same value or exception as the given CompletionStage when that completes. Transformations of the returned Future are executed asynchronously as specified by the ExecutionContext that is given to the combinator methods.

    cs

    The CompletionStage which may eventually supply the completion for the returned Scala Future

    returns

    a Scala Future that represents the CompletionStage's completion

  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped