Created
June 26, 2019 08:45
-
-
Save gotoweb/c42ecfb79f1a9e0253d35e0e1e40cea1 to your computer and use it in GitHub Desktop.
ordering-coffee-sync.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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