🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

Your own Promise.all

↗ Quelle (dev.to)
🗣️ Stimme:

In modern JavaScript development, handling asynchronous operations efficiently is essential, especially when multiple tasks need to run simultaneously. That’s where Promise.all comes in—a powerful method that allows you to execute several promises at once, waiting for all of them to resolve (or for one to reject) before proceeding. In this post, we’ll dive into how Promise.all works, why it’s such a valuable tool for managing concurrent asynchronous operations, and how you can implement it yourself to deepen your understanding of JavaScript promises.

Let’s get started!



Example usage




CODE
const p1 = Promise.resolve(1)
const p2 = Promise.resolve(2)
const p3 = Promise.resolve(3)

customPromiseAll([p1, p2, p3])
.then((res) => console.log(res))
.catch(console.error)






When we start writing the function, in order for the Promise to work at all, we’ll first return a new instance of Promise like this:




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {

})
}






Now, we’ll create a variable to hold the result of the function. It will be an array, and we’ll call it result. Additionally, we’ll create a variable named completed to keep track of the number of promises that have been completed.




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0


})
}






We’ll check an edge case: if the array of promises the function receives is empty, we’ll return an empty array as a resolved value and finish.




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0

if (promises.length === 0) {
resolve([])
}

})
}






If not, we’ll iterate over the array of promises the function receives using forEach and handle each resolve like this:




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0

if (promises.length === 0) {
resolve([])
}

promises.forEach((promise, index) => {
Promise.resolve(promise)
.then((value) => {

})
})
})
}






We’ll store each value in the results array at its designated index and increment completed by 1.




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0

if (promises.length === 0) {
resolve([])
}

promises.forEach((promise, index) => {
Promise.resolve(promise)
.then((value) => {
results[index] = value
completed++


})
})
})
}






Now, we’ll check if completed is equal to the length of the promises array. If it is, we’ve gone through all the items in the array, which means we’re done, so we’ll resolve the results array.




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0

if (promises.length === 0) {
resolve([])
}

promises.forEach((promise, index) => {
Promise.resolve(promise)
.then((value) => {
results[index] = value
completed++

if (completed === promises.length) {
resolve(results)
}
})
})
})
}






Finally, we’ll add .catch in case any of the promises return an error.




CODE
function customPromiseAll(promises) {
return new Promise((resolve, reject) => {
const results = []
let completed = 0

if (promises.length === 0) {
resolve([])
}

promises.forEach((promise, index) => {
Promise.resolve(promise)
.then((value) => {
results[index] = value
completed++

if (completed === promises.length) {
resolve(results)
}
})
.catch(reject) // Reject immediately if any promise fails
})
})
}


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Your own Promise.all

Thematisch verwandte Begriffe: Your, Promiseall · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...