The Promise API
This is a global object exposed within the browser. Some browsers do not currently support it as its part of the next version of JavaScript, known as ECMAScript 6. For those browsers we include a library which emulates the Promise object very closely so there should be no difference.
Promise.<User>
This example shows that User is the type of object that the promise resolves to.
promise.then(function(value) { // This function is invoked when the promise has // 'resolved' and the first argument passed in will // be the return value from the call made, if there is one. }).catch(function(error) { // You can chain the "then" and "catch" calls on a promise // The first argument passed into catch will be an Error // object explaining the error that occurred });
As you can see there are only two methods on a promise object, then and catch. They can be chained and you can also return a new value from a then or catch function that will be wrapped in a promise and sent on to the next in the chain.
Once a promise is resolved or rejected it will never change, it will only be settled once.
var tasks = [ view.getUser(), view.getScenarioProperties(0), view.start() ]; Promise.all(tasks).then(function(values) { // The resolved values are available in an array passed as the // first argument, in the same order as that defined // in the "tasks" array. var user = values[0]; var scenarioProperties = values[1]; }).catch(function(error) { console.error('could not start view. Reason: ' + error.message); });
© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.