ljharb on master
[eslint config] [base] [patch] … [eslint config] [patch] extend … Merge pull request #1996 from r… (compare)
ljharb on master
[editorial] [react] fix typo [eslint config] [*] [deps] upda… (compare)
if I replace this line of code
.then((text) => { throw new Error('Failed!') })
.catch(err => console.log(err))
.then(() => console.log('Does that execute?'));
with this
.then((text) => { console.log(text) ) })
.then(() => console.log('Does that execute?'));
Timer completed
and second Does this execute
Does this execute
will not be output until the timer is done
let myFirstPromise = new Promise((resolve, reject) => {
// We call resolve(...) when what we were doing asynchronously was successful, and reject(...) when it failed.
// In this example, we use setTimeout(...) to simulate async code.
// In reality, you will probably be using something like XHR or an HTML5 API.
setTimeout( function() {
resolve("Success!") // Yay! Everything went well!
}, 250)
})
myFirstPromise.then((successMessage) => {
// successMessage is whatever we passed in the resolve(...) function above.
// It doesn't have to be a string, but if it is only a succeed message, it probably will be.
console.log("Yay! " + successMessage)
});
Yay! Success
Success
function trackUserHandler() {
navigator.geolocation.getCurrentPosition(
(position) => {
setTimeout(() => {
console.log('Position ', position);
}, 2000);
},
(error) => console.log(error)
);
/**
* This line will run before we print
* current position or throw an error
*/
setTimeout(() => {
console.log('Timer done');
}, 1000);
console.log('Getting position');
}
button.addEventListener('click', trackUserHandler);
Getting position
will be executed immediately