const mySetTimeout = (delay) => {
return new Promise(res => setTimeout(res, delay));
}
const makeToy = async () => {
if(Math.floor(Math.random() * 2) === 1) {
console.log('makedToy');
} else {
console.log('toy not created');
}
}
const deliverToys = async (deliver) => {
if(deliver === 'makedToy') {
if(Math.floor(Math.random() * 2) > 1) {
console.log('delivered toy');
} else {
console.log('not delivered');
}
}
}
const toyShop = async () => {
try {
await mySetTimeout(3000);
const make = await makeToy();
await mySetTimeout(2000);
const deliver = await deliverToys(make);
Вот Здесь console.log(deliver);
} catch (error) {
console.log(error);
}
}
toyShop();