Skip to content

Commit ef69255

Browse files
committed
[프라미스 체이닝] upstream 병합 충돌 해결
1 parent 09f7b41 commit ef69255

1 file changed

Lines changed: 5 additions & 32 deletions

File tree

1-js/11-async/03-promise-chaining/article.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,18 @@ new Promise(function(resolve, reject) {
3434

3535
프라미스 체이닝은 `result``.then` 핸들러의 체인(사슬)을 통해 전달된다는 점에서 착안한 아이디어입니다.
3636

37-
<<<<<<< HEAD
3837
위 예시는 아래와 같은 순서로 실행됩니다.
3938
1. 1초 후 최초 프라미스가 이행됩니다. -- `(*)`
40-
2. 이후 첫번째 `.then` 핸들러가 호출됩니다. --`(**)`
41-
3. 2에서 반환한 값은 다음 `.then` 핸들러에 전달됩니다. -- `(***)`
39+
2. 이후 첫 번째 `.then` 핸들러가 호출됩니다. 결괏값이 2인 새로운 프라미스를 생성합니다. --`(**)`
40+
3. 다음 `.then`은 이전 결과를 받아 처리하고(두 배로 증가) 다음 핸들러에 전달합니다. -- `(***)`
4241
4. 이런 과정이 계속 이어집니다.
43-
=======
44-
Here the flow is:
45-
1. The initial promise resolves in 1 second `(*)`,
46-
2. Then the `.then` handler is called `(**)`, which in turn creates a new promise (resolved with `2` value).
47-
3. The next `then` `(***)` gets the result of the previous one, processes it (doubles) and passes it to the next handler.
48-
4. ...and so on.
49-
>>>>>>> upstream/master
5042

5143
`result`가 핸들러 체인을 따라 전달되므로, `alert` 창엔 `1`, `2`, `4`가 순서대로 출력됩니다.
5244

5345
![](promise-then-chain.svg)
5446

55-
<<<<<<< HEAD
56-
프라미스 체이닝이 가능한 이유는 `promise.then`을 호출하면 프라미스가 반환되기 때문입니다. 반환된 프라미스엔 당연히 `.then`을 호출할 수 있습니다.
57-
=======
58-
The whole thing works, because every call to a `.then` returns a new promise, so that we can call the next `.then` on it.
59-
>>>>>>> upstream/master
47+
프라미스 체이닝이 가능한 이유는 `.then`을 호출할 때마다 새로운 프라미스가 반환되기 때문입니다. 반환된 프라미스엔 당연히 `.then`을 호출할 수 있습니다.
48+
6049

6150
한편 핸들러가 값을 반환할 때엔 이 값이 프라미스의 `result`가 됩니다. 따라서 다음 `.then`은 이 값을 이용해 호출됩니다.
6251

@@ -84,11 +73,7 @@ promise.then(function(result) {
8473
});
8574
```
8675

87-
<<<<<<< HEAD
88-
예시의 프라미스는 하나인데 여기에 등록된 핸들러는 여러 개 입니다. 이 핸들러들은 `result`를 순차적으로 전달하지 않고 독립적으로 처리합니다.
89-
=======
90-
What we did here is just adding several handlers to one promise. They don't pass the result to each other; instead they process it independently.
91-
>>>>>>> upstream/master
76+
예시의 프라미스는 하나인데 여기에 등록된 핸들러는 여러 개입니다. 이 핸들러들은 `result`를 순차적으로 전달하지 않고 독립적으로 처리합니다.
9277

9378
그림으로 표현하면 다음과 같습니다. 프라미스 체이닝을 묘사한 위 그림과 비교해 보세요.
9479

@@ -136,12 +121,8 @@ new Promise(function(resolve, reject) {
136121
});
137122
```
138123

139-
<<<<<<< HEAD
140124
예시에서 첫 번째 `.then``1`을 출력하고 `new Promise(…)`를 반환(`(*)`)합니다.
141125
1초 후 이 프라미스가 이행되고 그 결과(`resolve`의 인수인 `result * 2`)는 두 번째 `.then`으로 전달됩니다. 두 번째 핸들러(`(**)`)는 `2`를 출력하고 동일한 과정이 반복됩니다.
142-
=======
143-
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to the handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
144-
>>>>>>> upstream/master
145126

146127
따라서 얼럿 창엔 이전 예시와 동일하게 1, 2, 4가 차례대로 출력됩니다. 다만 얼럿 창 사이에 1초의 딜레이가 생깁니다.
147128

@@ -245,11 +226,7 @@ new Promise(resolve => resolve(1))
245226

246227
## fetch와 체이닝 함께 응용하기
247228

248-
<<<<<<< HEAD
249229
프론트 단에선, 네트워크 요청 시 프라미스를 자주 사용합니다. 이에 관련된 예시를 살펴봅시다.
250-
=======
251-
In frontend programming, promises are often used for network requests. So let's see an extended example of that.
252-
>>>>>>> upstream/master
253230

254231
예시에선 메서드 [fetch](info:fetch)를 사용해 원격 서버에서 사용자 정보를 가져오겠습니다. `fetch`엔 다양한 선택 매개변수가 있는데 자세한 내용은 [별도의 챕터](info:fetch)에서 다루기로 하고, 여기선 기본 문법만 사용해 보겠습니다.
255232

@@ -290,11 +267,7 @@ fetch('/article/promise-chaining/user.json')
290267

291268
불러온 사용자 정보를 가지고 무언가를 더 해보겠습니다.
292269

293-
<<<<<<< HEAD
294270
GitHub에 요청을 보내 사용자 프로필을 불러오고 아바타를 출력해 보는 것같이 말이죠.
295-
=======
296-
For instance, we can make one more request to GitHub, load the user profile and show the avatar:
297-
>>>>>>> upstream/master
298271

299272
```js run
300273
// user.json에 요청을 보냅니다.

0 commit comments

Comments
 (0)