Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
interface Product { id: number; name: string; price: number; } async function fetchProduct(id: number): Promise
{ console.log(`Fetching product ${id}...`); await new Promise(resolve => setTimeout(resolve, Math.random() * 1000)); return { id, name: `Product ${id}`, price: Math.floor(Math.random() * 100) }; } async function fetchMultipleProducts() { try { // Start all fetches in parallel const [product1, product2, product3] = await Promise.all([ fetchProduct(1), fetchProduct(2), fetchProduct(3), ]); const total = [product1, product2, product3] .reduce((sum, product) => sum + product.price, 0); console.log(`Total price: $${total.toFixed(2)}`); } catch (error) { console.error("Error fetching products:", error); } } fetchMultipleProducts();
Expected console output:
Total price: $50.00