Represents the result of an action that may, or may not, have occurred yet.

  • Future
    • Basic
      • Identifiable
      • Object
        • Anything
Initializer
Future(Future<out Object> unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
causeshared default Throwable cause()

A Throwable describing failure. This will be null if the operation succeeded.

completeshared default void complete()

Set a null result. Any handler will be called, if there is one, and the future will be marked as completed.

completeshared default void complete(T result)

Set the result. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • result

    the result

completershared default Anything(Throwable|T) completer()
composeshared default Future<U?> compose<U>(Future<U?>(T) mapper)

Compose this future with a mapper function.

When this future (the one on which compose is called) succeeds, the mapper will be called with the completed value and this mapper returns another future object. This returned future completion will complete the future returned by this method call.

If the mapper throws an exception, the returned future will be failed with this exception.

When this future fails, the failure will be propagated to the returned future and the mapper will not be called.

Parameters:
  • mapper

    the mapper function

composeshared default Future<U?> compose<U>(Anything(T) handler, Future<U?> next)

Compose this future with a provided next future.

When this (the one on which compose is called) future succeeds, the handler will be called with the completed value, this handler should complete the next future.

If the handler throws an exception, the returned future will be failed with this exception.

When this future fails, the failure will be propagated to the next future and the handler will not be called.

Parameters:
  • handler

    the handler

  • next

    the next future

failshared default void fail(String failureMessage)

Try to set the failure. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • failureMessage

    the failure message

failshared default void fail(Throwable cause)

Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • cause

    the failure cause

failedshared default Boolean failed()

Did it fail?

isCompleteshared default Boolean isComplete()

Has the future completed?

It's completed if it's either succeeded or failed.

mapshared default Future<U?> map<U>(U?(T) mapper)

Apply a mapper function on this future.

When this future succeeds, the mapper will be called with the completed value and this mapper returns a value. This value will complete the future returned by this method call.

If the mapper throws an exception, the returned future will be failed with this exception.

When this future fails, the failure will be propagated to the returned future and the mapper will not be called.

Parameters:
  • mapper

    the mapper function

mapshared default Future<V?> map<V>(V? value)

Map the result of a future to a specific value.

When this future succeeds, this value will complete the future returned by this method call.

When this future fails, the failure will be propagated to the returned future.

Parameters:
  • value

    the value that eventually completes the mapped future

mapEmptyshared default Future<V?> mapEmpty<V>()

Map the result of a future to null.

This is a conveniency for future.map((T) null) or future.map((Void) null).

When this future succeeds, null will complete the future returned by this method call.

When this future fails, the failure will be propagated to the returned future.

otherwiseshared default Future<T> otherwise(T value)

Map the failure of a future to a specific value.

When this future fails, this value will complete the future returned by this method call.

When this future succeeds, the result will be propagated to the returned future.

Parameters:
  • value

    the value that eventually completes the mapped future

otherwiseshared default Future<T> otherwise(T(Throwable) mapper)

Apply a mapper function on this future.

When this future fails, the mapper will be called with the completed value and this mapper returns a value. This value will complete the future returned by this method call.

If the mapper throws an exception, the returned future will be failed with this exception.

When this future succeeds, the result will be propagated to the returned future and the mapper will not be called.

Parameters:
  • mapper

    the mapper function

otherwiseEmptyshared default Future<T> otherwiseEmpty()

Map the failure of a future to null.

This is a convenience for future.otherwise((T) null).

When this future fails, the null value will complete the future returned by this method call.

When this future succeeds, the result will be propagated to the returned future.

recovershared default Future<T> recover(Future<T>(Throwable) mapper)

Handles a failure of this Future by returning the result of another Future. If the mapper fails, then the returned future will be failed with this failure.

Parameters:
  • mapper

    A function which takes the exception of a failure and returns a new future.

resultshared default T result()

The result of the operation. This will be null if the operation failed.

setHandlershared default Future<T> setHandler(Anything(Throwable|T) handler)

Set a handler for the result.

If the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.

Parameters:
  • handler

    the Handler that will be called with the result

succeededshared default Boolean succeeded()

Did it succeed?

tryCompleteshared default Boolean tryComplete()

Try to set the result. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

tryCompleteshared default Boolean tryComplete(T result)

Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • result

    the result

tryFailshared default Boolean tryFail(String failureMessage)

Try to set the failure. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • failureMessage

    the failure message

tryFailshared default Boolean tryFail(Throwable cause)

Try to set the failure. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

Parameters:
  • cause

    the failure cause

Inherited Methods
Methods inherited from: Object
equals