Mistakes we make using JavaScript Promises
betamark.com
Mistakes we make using JavaScript Promises
1–10 of 60 posts
Re: Mistakes we make using JavaScript Promises
#2Re: Mistakes we make using JavaScript Promises
#3And he makes mistake #1 in mistake #3 by running „get“ sequentially instead of using Promise.all
Re: Mistakes we make using JavaScript Promises
#4And he makes mistake #1 in mistake #3 by running „get“ sequentially instead of using Promise.all
They're all artificial examples: one could assume that the tasks in #3 are intended to be executed serially. Though there aren't any data dependencies expressed between the different calls, perhaps ordering could be important for other reasons.
Re: Mistakes we make using JavaScript Promises
#5Re: Mistakes we make using JavaScript Promises
#6 get("http://data.com/user")
.then(user => get("http://data.com/location" + user.id))
.then(location => createEntry(user, location))
.then(response => {
// handle response
}).catch(err => {
// handle failure
});
Instead, back before async/await made things easier this nested pattern was used (notice the difference in parenthesis location): get("http://data.com/user")
.then(user => get("http://data.com/location" + user.id)
.then(location => createEntry(user, location)))
.then(response => {
// handle response
}).catch(err => {
// handle failure
});
Edit for completeness, this is how it is now with async/await: try {
const user = await get("http://data.com/user");
const location = await get("http://data.com/location" + user.id);
const response = await createEntry(user, location);
// handle response
} catch (error) {
// handle failure
}Re: Mistakes we make using JavaScript Promises
#7Re: Mistakes we make using JavaScript Promises
#8Re: Mistakes we make using JavaScript Promises
#9"Ethereum Phishing Detection"
This domain is currently on the MetaMask domain warning list
Re: Mistakes we make using JavaScript Promises
#10Earlier quoted context omitted.
They're all artificial examples: one could assume that the tasks in #3 are intended to be executed serially. Though there aren't any data dependencies expressed between the different calls, perhaps ordering could be important for other reasons.
I feel it should have been called out explicitly when introducing await, because the 'clean' solution in async/await code is to call each async function and then await the results where you need them - which is a pattern he doesn't hint at at all.