Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Promise<T>

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

The {@link Promise#future} method returns the {@link Future} associated with a promise, the future can be used for getting notified of the promise completion and retrieve its value.

A promise extends Handler> so it can be used as a callback.

Type parameters

  • T

Hierarchy

  • Promise

Index

Methods

complete

  • complete(result: T): void
  • complete(): void
  • Set the result. Any handler will be called, if there is one, and the promise will be marked as completed.

    Any handler set on the associated promise will be called.

    Parameters

    • result: T

    Returns void

  • Calls complete(null)

    Returns void

fail

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

    Parameters

    Returns void

  • Calls {@link Promise#fail} with the message.

    Parameters

    • message: string

    Returns void

future

  • future(): PromiseLike<T>
  • Returns PromiseLike<T>

tryComplete

  • tryComplete(result: T): boolean
  • tryComplete(): boolean
  • Like {@link Promise#complete} but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.

    Parameters

    • result: T

    Returns boolean

  • Calls tryComplete(null).

    Returns boolean

tryFail

  • tryFail(cause: Throwable | Error): boolean
  • tryFail(message: string): boolean
  • Like {@link Promise#fail} but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.

    Parameters

    Returns boolean

  • Calls {@link Promise#fail} with the message.

    Parameters

    • message: string

    Returns boolean

Static promise

  • Create a promise that hasn't completed yet

    Type parameters

    • T

    Returns Promise<T>

Generated using TypeDoc