Skip to content

[문제] 프로미스 이용 시, 주의해야할 점 #21

Description

@live-small

질문

프로미스를 이용할 때, 주의해야할 점은 뭐가 있을까요?

상세내용

JS엔진은 콜스택을 1개 가지기에 이를 구동하는 브라우저, node.js에서 동시성이 가능하게 지원해줍니다.

Web API중 하나인 setTimeout : 콜스택 push & pop -> task queue에 push
Promise : 콜스택 push & pop -> micro task queue에 push
콜스택이 비었을 때, 이벤트루프의 우선순위에 따라 제일 오래된 작업부터 콜스택에 옮겨 수행됩니다.
*이벤트루프 우선순위: micro task queue > task queue

이벤트루프 우선순위로 인해 태스크큐에 있는 작업이 밀리는 경우
예를들어, UI와 직결된 클릭, 텍스트 입력, 렌더링과 같은 이벤트가 가로 막힐 수 있습니다.

관련 챕터

45장 프로미스

참고

프로미스 활용 시, 고려해야할 부분- LINE 기술블로그
이벤트루프 동작방식 시각화

읽어볼만한 것

node.js - 이벤트 루프

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions