JavaScript'te Async/Await: Kapsamlı Rehber
Asenkron programlamayı doğru anlayın
Promise vs Async/Await:
// Promise
fetch(url)
.then(r => r.json())
.then(data => console.log(data))
.catch(err => console.error(err));
// Async/Await
async function getData() {
try {
const r = await fetch(url);
const data = await r.json();
console.log(data);
} catch(err) {
console.error(err);
}
}
Paralel İstekler:
const [users, posts] = await Promise.all([
fetch("/api/users").then(r => r.json()),
fetch("/api/posts").then(r => r.json()),
]);
Kategori:
React
Bu konuyu EL11.Net forumunda tartışmak ister misiniz?
Forumda Gör