Middle
// Konsolda ne gösterilir ? const p1 = Promise.resolve(1); const p2 = new Promise((_, reject) => setTimeout(() => reject("Error"), 100)); const p3 = Promise.resolve(3); Promise.all([p1, p2, p3]) .then(console.log) .catch(console.error); Promise.allSettled([p1, p2, p3]).then(console.log);
sobes.tech yapay zeka
AI'dan gelen yanıt
Konsolda aşağıdaki gibi görüntülenir:
Promise.all([p1, p2, p3])çağrısı hata ile sona erecek, çünküp2100 ms sonra "Error" mesajı ile reddedilir. Bu nedenle.catch(console.error)bloğunda şu gösterilir:
Error
Promise.allSettled([p1, p2, p3])çağrısı her zaman başarılı olur ve tüm promise sonuçlarını içeren bir dizi döner, durumları ne olursa olsun. Konsolda şu nesne dizisi gösterilir:
[
{ status: "fulfilled", value: 1 },
{ status: "rejected", reason: "Error" },
{ status: "fulfilled", value: 3 }
]
Bu nedenle önce Promise.all hatası konsola yansır, ardından Promise.allSettled sonuç dizisi gelir.