javaScript/js.Asynchronous

비동기 프로그래밍

동기식 처리 모델(Synchronous processing model)

  • 태스크를 순차적으로 하나씩 처리하는 방식
  • 현재 실행중인 태스크가 종료할 때까지 다음 실행될 태스크가 대기하는 방식
  • 앞선 태스크가 종료할 때 까지 이후 태스크들이 블로킹된다는 단점

비동기식 처리모델(Asynchronous processing model)

  • 현재 실행중인 태스크가 종료되지 않은 상태라 하더라도 다음 태스크를 곧바로 실행하는 방식
  • setTimeout은 일정 시간 경과한 후에 콜백 함수를 호출하지만 이후 태스크들을 블로킹하지 않고 곧바로 실행
  • 타이머 함수, Ajax 요청, 이벤트 처리는 비동기식 처리모델
1
2
3
4
5
6
7
8
9
10
11
function foo() {
console.log('foo');
}

function bar() {
console.log('bar');
}

setTimeout(foo, 3 * 1000);
bar();
// bar ->(3초 경과후) foo
You forgot to set the qrcode for Alipay. Please set it in _config.yml.
You forgot to set the qrcode for Wechat. Please set it in _config.yml.
You forgot to set the business and currency_code for Paypal. Please set it in _config.yml.
You forgot to set the url Patreon. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×