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

[wook] step 13-1 미션 제출합니다! #74

Merged
merged 8 commits into from Jul 4, 2019

Conversation

pocokim
Copy link

@pocokim pocokim commented Jul 4, 2019

요구사항만 동작하는 myPromise 입니다!

resolve에서 while문을 돌면서 myPromise 의 콜백큐에 등록된 콜백들을 실행합니다.
then함수는 새로운 myPromise를 리턴하게 만드려고 했는데.. 그러지 못한게 아쉽네요 ㅠㅠ

snow pc에서 작업하던 파일을 제가 다시 clone해서 구현하여 commit이 남아있지 않게 되었습니다 ㅠㅠ
constructor 에서 cb를 실행하도록 하였다.
cb가 MyPromise.resolve와 MyPromise.reject를 인자로 받도록하였다.
콜백함수의 인자를 외부에서 받아서 처리하는것이 아니므로
내부의 this.value를 인자로 넣어주어 Promise객체가 인자로 들어가도록 처리하였다.
then은 내부에서 cb가 상태가 변했을때 실행되도록한다.
따라서 resolve에서 상태를 바꾸고, then을 한번 더 호출해야한다.
이에따라 then의 콜백함수를 변수로 기억하도록 하였다. (변수가 하나 더 생겨서 살짝 지저분한것같다)
fast-return 을 사용해 2뎁스를 예방
1. this.callback를 this.callbackQueue로 변경
2. executeThensCallback 함수를 생성
이 함수는 등록된 콜백함수를 실행하고 promise 객체의 value를 변경하고 콜백큐를 수정하며 resolve에서 실행된다.
3. 하나의 promise에서 실행되므로 resolve에서 while문을 통해 콜백큐에 등록된 콜백들을 실행한다.

4. 그러나 이런 방식은 Promise생성시 pending이 resolve로 바뀌면 나머지 Promise는 자동으로 resolve상태로 담아있게된다.
step12-1 작업 머지 받아오기
Copy link
Contributor

@crongro crongro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요구사항대로 잘 구현했네요.
진짜 프라미스는 다양한 조건으로 동작하고, 복잡하죠.
실제로 then함수는 계속 새로운 promise객체를 반환한다고 하네요 😮


resolve(value) {
this.value = value;
this.state = 'fulfilled';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

promise가 fullfilled / rejected 이런 상태를 가지고 있죠.
이번기회에 의미를 잘 기억해두세요.

}).then((data2) => {
console.log(`data2 인 ${data2}를 잘 받았습니다.`);
return data2
}).then((data3) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(계속 같은 data네요 ㅎㅎ)
아무튼 잘 했어요.

@crongro crongro merged commit 86403fa into code-squad:wo0kgod Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants