Skip to content

Instantly share code, notes, and snippets.

@gotoweb
Created June 26, 2019 08:45
Show Gist options
  • Save gotoweb/c42ecfb79f1a9e0253d35e0e1e40cea1 to your computer and use it in GitHub Desktop.
Save gotoweb/c42ecfb79f1a9e0253d35e0e1e40cea1 to your computer and use it in GitHub Desktop.
ordering-coffee-sync.js
function waitSync(ms) {
var start = Date.now();
var now = start;
while(now - start < ms) {
now = Date.now();
}
} // 현재 시각과 시작 시각을 비교하며 ms 범위 내에서 무한 루프를 도는 blocking 함수입니다
function drink(person, coffee) {
console.log(person + '는 ' + coffee + '를 마십니다');
}
function orderCoffeeSync(coffee) {
console.log(coffee + '가 접수되었습니다');
waitSync(2000);
return coffee;
}
let customers = [{
name: 'Steve',
request: '카페라떼'
}, {
name: 'John',
request: '아메리카노'
}];
// call synchronously
customers.forEach(function(customer) {
let coffee = orderCoffeeSync(customer.request);
drink(customer.name, coffee);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment