Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
live-small opened this issue Sep 18, 2021 · 1 comment
Open

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

live-small opened this issue Sep 18, 2021 · 1 comment
Labels

Comments

@live-small
Copy link
Owner

질문

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

상세내용

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 - 이벤트 루프

@jessi68
Copy link
Collaborator

jessi68 commented Oct 2, 2021

promise 를 이용할 때, promise 는 비동기 프로그래밍을 할 때 사용하는 객체 이고, 비동기 프로그래밍은 코드가 적힌 순서가 곧 실행 순서라는 보장이 없기 때문에 부분 부분 순서를 정해 줄 필요가 있을 때에는 await async 등을 적절히 활용해 줘야 된다는 점을 주의해야 한다고 생각합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants