Skip to content
Open

reto #12

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const orders = (time, product, table) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`=== Pedido servido: ${product}, tiempo de preparación ${time}ms para la ${table}`);
reject(new Error("Error!"));
}, time);
});
}
Expand All @@ -15,10 +16,46 @@ const menu = {

const table = ['Mesa 1', 'Mesa 2', 'Mesa 3', 'Mesa 4', 'Mesa 5'];


const randomTime = () => {
const min = 1000;
const max = 8000;
return Math.round(Math.random() * (max - min)) + min;
};

const waiter = () => {
orders(6000, menu.hamburger, table[3])
.then((res) => console.log(res))
.catch((err) => console.error(err));
};

waiter();
waiter()


const waiter2 = () => {
orders(randomTime(), menu.hotdog, table[0])
.then(res => {
console.log(res);
return orders(randomTime(), menu.pizza, table[2]);
})
.then(res => console.log(res))
.catch(err => console.error(err));
};

waiter2()

async function waiter3() {
try {
const listOrders = [
await orders(randomTime(), menu.hotdog, table[1]),
await orders(randomTime(), menu.pizza, table[1]),
await orders(randomTime(), menu.hotdog, table[1])
];
const res = await Promise.all(listOrders);
console.log(res);
} catch (err) {
console.error(err);
}
}
waiter3();