Java Reference
In-Depth Information
These phases allow you to specify which code to run for each part of the operation.
A promise is created using a constructor function. This takes a function called an executor
as an argument where it's possible to state the conditions for success and failure:
var promise = new Promise(
function (resolve, reject) {
if (...) { // condition for success goes here
resolve(value); // success
} else {
reject(reason); // failure
Now the promise is stored in a variable—called promise in this case—where it's possible
to call methods on the promise. The then() method gives a readable way of specifying
what needs to be done once the operation is successful:
function (value) {
// success code here
The catch() method is used to specify what to do if the operation fails:
function (reason) {
// failure code here
Harmony will also introduce support for generators . These are special functions used to
produce iterators that maintain the state of a value. [9]
Search WWH ::

Custom Search