AWAITRACE (Promises, OnSuccess?, OnFailure?) AWAITRACE (Promises; OnSuccess?; OnFailure?)

Promises

The promises.

OnSuccess

A formula fragment that is run when the first promise succeeds. The result returned by this promise is available under the name Result and the position of this promise in the promises array is available under the name Index .

OnFailure

A formula fragment that is run when the first promise fails. The error returned by this promise is available under the name Error and the position of this promise in the promises array is available under the name Index .

Returns

A promise, which succeeds when the first of the given promises succeeds and fails when the first of the given promises fails. If the promise succeeds, the returned value is the result of the promise that succeeded. If the promise fails, the returned value is the error of the promise that failed.

Waits for the first of multiple promises to return a response before running an action. This function can only be used from an action formula. AWAITRACE and other similar functions are used to take action when a promise succeeds or fails.

The first parameter to AWAITRACE must be an array of promises . A function returning such a value promises to return a value at some point in the future, or at the very least indicate whether the operation the function started was successful. A promise either succeeds or fails, and it can only succeed or fail once.

AWAITRACE waits for a promise to return a result, and runs the formula fragment given as its second parameter if the promise has succeeded. It runs the formula fragment given as its third parameter if the promise has failed.

The second parameter, if invoked, has access to the result returned by the promise under the name Result and the position of this promise in the promises array under the name Index .

The formula fragment given as the third parameter to AWAITRACE is run if the first promise to return a result has failed. The error returned by the promise is available under the name Error and the position of this promise in the promises array is available under the name Index .

This is different from how AWAITANY works. Both functions perform identically when handling promises that succeed, but handle errors differently. AWAITANY waits for all promises to fail before running the formula fragment given as its third parameter. AWAITRACE, on the other hand, invokes the formula fragment given as its third parameter immediately if the first promise to return a result has failed.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell