function waitSync(ms) {
let start = Date.now();
let now = start;
while(now-start < ms) {
noew = Date.now();
}
}
function drink(person, coffee) {
console.log(person + '는 ' + '를 마십니다');
}
function orderCoffeeSync(coffee) {
console.log(coffee + '가 접수되었습니다');
waitSync(2000);
return coffee;
}
let customers = [
{ name: 'Steve', request: '카페라떼' },
{ name: 'John', request: '아메리카노'}
];
customers.forEach( customer => {
let coffee = orderCoffeeSync(customer.request);
drink(customer.name, coffee);
})
function waitAsync(cb, ms) {
setTimeout(cb,ms);
}
function drink(person, coffee) {
console.log(person + '는 ' + '를 마십니다');
}
function orderCoffeeAsync(menu, callback) {
console.log(menu + '가 접수되었습니다');
waitAsync(function() {
callback(menu);
}, 4000);
}
let customers = [
{ name: 'Steve', request: '카페라떼' },
{ name: 'John', request: '아메리카노'}
];
customers.forEach( customer => {
orderCoffeeAsync(customer.request, coffee => {
drink(customer.name, coffee);
});
});