Oracle Magazine, Nov/Dec 2017
Database Developer OPEN SOURCE const promise3 new Promise function resolve reject reject new Error ouch ORACLE MAGAZINE NOVEMBER OCTOBER 2017 48 console log promise3 If you run the script above in either a web browser or Node js you should see output similar to the following I used Chrome and then modified the output to fit better on the page For now ignore any errors related to uncaught or unhandled promise rejections Theres more on uncaught or unhandled promise rejections later Promise Status pending Value undefined Promise Status resolved Value woohoo Promise Status rejected Value Error ouch at As you can see the first promise has a status of pending and no value because neither the resolve nor reject function was used The second promise which was resolved with the resolve function is in the resolved state and its value is woohoo the value passed to the resolve function The last promises state is rejected because it was rejected with the reject function and its value is the error that was passed to reject Note that this demo script is completely synchronous Typically promises are resolved or rejected depending on the result of invoking one or more asynchronous APIs Once a promise has been resolved or rejected its state and value become immutable
You must have JavaScript enabled to view digital editions.