About Parallel Promises
In JavaScript, you can run multiple promises in parallel and then collect the results together:
let promise1 = new Promise(function(resolve, reject) {
// get the data…
resolve(data);
});
let promise2 = new Promise(function(resolve, reject) {
// get the data…
resolve(data);
});
let promise3 = new Promise(function(resolve, reject) {
// get the data…
resolve(data);
});
Promise.all([promise1, promise2, promise3]).then(
([data1, data2, data3]) => {
// do something with data from all three promises…
}
).catch(err => {
console.error(err);
});
For clarification, there are no threads in JavaScript. That is, if you use normal conditions and loops to get the data for your promises, they will be executed consecutively.
But if you use timeouts, Ajax calls, or web workers in the promises, they will act like asynchronous threads.
Also by me
Django Messaging
For Django-based social platforms.
Django App for You
Django Paddle Subscriptions
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent
For Django websites that use cookies.
Django App for You