Javascript Promise
Menu JS Promise
 

The JavaScript Promise Object

The concept of a Promise Object was discussed when I was analysing the behaviour of asynchronous data exchange with a webserver.

In addition to this research the Fetch() API was also discussed.

According to W3C Schools:

" A JavaScript Promise object contains both the producing code and calls to the consuming code. "

let myPromise = new Promise(function(myResolve, myReject) {
// "Producing Code" (May take some time)

   myResolve(); // when successful
   myReject(); // when error
});

// "Consuming Code" (Must wait for a fulfilled Promise)
myPromise.then(
   function(value) { /* code if successful */ },
   function(error) { /* code if some error */ }
);

What MDN say:

A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.

The explanation on the W3C page for the Fetch API gives an example that says that Fetch is based on asyc and await. It then goes on to simplify the explanation, but I found that it didn't really help. The second example actually uses async and wait. There is a third example using "understandable" names for variables.

Top

Links

External Links Disabled.

tempusfugit.me.uk is a non-commercial website. No payment or benefit is gained by the placement of links toother websites.

The External link is disabled to on this page, please visit other pages

Unlike most genealogical research websites tempusfugit.me.uk does not attempt to get you to "sign-up" when you click on one of their links.

This Wikipedia link is disabled.

The link on Wikipedia was to:

External Links Disabled.

tempusfugit.me.uk is a non-commercial website. No payment or benefit is gained by the placement of links to other websites.

The External link is disabled to on this page, please visit other pages

Top

External Links - references

Site design by Tempusfugit Web Design -