PromiseHandle CLASS

A handle exposed to the callback to manipulate promise result explicitly.

The promise normally sets its state by convention. If the function running in the promise completes successfully it will set the promise to RESOLVED. If the function throws an exception which went unhandled the promise will turn to REJECTED. By the time a follow-up promise runs the state is reset to PENDING, but depending on what continuation function gets invoked the state may get carried over from the previous promise.

Without explicit interference through the handle, the RESOLVED state will continue to be propagated down the chain, unless the continuation function on success throws; the REJECTED state will do the same, unless the continuation function on error completes successfully.

Through the handle, however, the continuation logic can explicitly set the state of the current promise. This is useful in many scenarios, such as forcing the abortion without exception-based logic control, or restoring the state in a promise handling a rejected antecedent. Moreover this can be used to control the state of a synthesized promise.

Once the promise is resolved this way, it cannot be explicitly set to REJECTED through the same handle. However, a following unhandled exception within the same callback may overwrite the state.

Parent Class

All Members


TypeNameSignature
methodrejectpublic void reject()
methodrejectpublic void reject(string)
methodrejectpublic void reject(System.Exception)
methodresolvepublic void resolve()
methodresolvepublic void resolve(var)

Methods


public void reject()

Reject the promise controlled by this handle, with a default cause. Calling Promise.getResult() will return or throw a PromiseRejectedException.


public void reject(string msg)

Reject the promise controlled by this handle, with a specified message. Calling Promise.getResult() will return or throw a PromiseRejectedException that contains this message.

Parameters


public void reject(Exception ex)

Reject the promise controlled by this handle, with a specified exception. Calling Promise.getResult() will return or throw this exception.

Parameters

  • ex An exception to set as the cause of rejection.

public void resolve()

Resolve the promise controlled by this handle, without setting any data. Calling Promise.getResult() will return null.


public void resolve(var result)

Resolve the promise controlled by this handle with specific data.

Parameters

  • result The end result to settle this promise. This is the value to be returned by Promise.getResult().