Skip to content

Commit db10ccf

Browse files
Merge pull request #1854 from gusdn3477/gusdn3477/sync-c28
[문서] C28 충돌 해결
2 parents fc4d67b + 02fb3e6 commit db10ccf

5 files changed

Lines changed: 166 additions & 452 deletions

File tree

5-network/02-formdata/article.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ HTML에 `form` 요소가 있는 경우, 위와 같은 코드를 작성하면 해
4747
</script>
4848
```
4949

50-
<<<<<<< HEAD
51-
요청을 받아 처리하는 서버 측 코드는 튜토리얼 범위를 넘어서서 추가하진 않았는데, 서버는 POST 요청을 받아 '저장 성공'이라는 응답을 보내준다고 정도만 알고 계시면 됩니다.
52-
=======
53-
In this example, the server code is not presented, as it's beyond our scope. The server accepts the POST request and replies "User saved".
54-
>>>>>>> upstream/master
50+
이 예시에서는 서버 코드가 튜토리얼 범위를 벗어나므로 제시하지 않습니다. 서버는 POST 요청을 받고 "사용자 정보 저장 성공"이라고 응답합니다.
5551

5652
## FormData 메서드
5753

@@ -172,11 +168,7 @@ formData.append("image", imageBlob, "image.png");
172168

173169
[FormData](https://xhr.spec.whatwg.org/#interface-formdata) 객체는 `fetch` 등의 네트워크 메서드를 통해 HTML 폼을 보내는데 사용됩니다.
174170

175-
<<<<<<< HEAD
176171
`FormData` 객체는 HTML 폼(`form`)을 직접 넘겨 `new FormData(form)`으로 만들 수도 있고, HTML 폼 없이 다음과 같은 메서드로 필드를 추가해 만들 수도 있습니다.
177-
=======
178-
We can either create `new FormData(form)` from an HTML form, or create an object without a form at all, and then append fields with methods:
179-
>>>>>>> upstream/master
180172

181173
- `formData.append(name, value)`
182174
- `formData.append(name, blob, fileName)`
Lines changed: 54 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,60 @@
11

2-
# Fetch: Abort
2+
# Fetch: 요청 중단하기
33

4-
As we know, `fetch` returns a promise. And JavaScript generally has no concept of "aborting" a promise. So how can we cancel an ongoing `fetch`? E.g. if the user actions on our site indicate that the `fetch` isn't needed any more.
4+
`fetch`는 프라미스를 반환합니다. 그런데 자바스크립트에는 일반적으로 프라미스를 '중단'한다는 개념이 없습니다. 그렇다면 진행 중인 `fetch`는 어떻게 취소할 수 있을까요? 예를 들어 사이트에서 사용자 행동을 보고 더 이상 `fetch`가 필요 없다고 판단한 경우처럼 말이죠.
55

6-
There's a special built-in object for such purposes: `AbortController`. It can be used to abort not only `fetch`, but other asynchronous tasks as well.
6+
이런 목적을 위해 만들어진 특별한 내장 객체가 있습니다. 바로 `AbortController`입니다. `AbortController`를 사용하면 `fetch`뿐만 아니라 다른 비동기 작업도 중단할 수 있습니다.
77

8-
The usage is very straightforward:
8+
사용법은 아주 간단합니다.
99

10-
## The AbortController object
10+
## AbortController 객체
1111

12-
Create a controller:
12+
컨트롤러를 하나 만듭니다.
1313

1414
```js
1515
let controller = new AbortController();
1616
```
1717

18-
A controller is an extremely simple object.
18+
컨트롤러는 아주 단순한 객체입니다.
1919

20-
- It has a single method `abort()`,
21-
<<<<<<< HEAD
22-
- And a single property `signal` that allows to set event liseners on it.
23-
=======
24-
- And a single property `signal` that allows to set event listeners on it.
25-
>>>>>>> upstream/master
20+
- 메서드는 `abort()` 하나뿐입니다.
21+
- 이벤트 리스너를 설정할 수 있는 프로퍼티도 `signal` 하나뿐입니다.
2622

27-
When `abort()` is called:
28-
- `controller.signal` emits the `"abort"` event.
29-
- `controller.signal.aborted` property becomes `true`.
23+
`abort()`가 호출되면 다음 일이 일어납니다.
24+
- `controller.signal`에서 `"abort"` 이벤트가 발생합니다.
25+
- `controller.signal.aborted` 프로퍼티 값이 `true`가 됩니다.
3026

31-
<<<<<<< HEAD
32-
Generally, we have two parties in the process:
33-
1. The one that performs an cancelable operation, it sets a listener on `controller.signal`.
34-
2. The one one that cancels: it calls `controller.abort()` when needed.
35-
=======
36-
Generally, we have two parties in the process:
37-
1. The one that performs a cancelable operation, it sets a listener on `controller.signal`.
38-
2. The one that cancels: it calls `controller.abort()` when needed.
39-
>>>>>>> upstream/master
27+
보통 이 과정에는 두 주체가 있습니다.
28+
1. 취소 가능한 작업을 수행하는 쪽은 `controller.signal`에 리스너를 설정합니다.
29+
2. 취소하는 쪽은 필요할 때 `controller.abort()`를 호출합니다.
4030

41-
Here's the full example (without `fetch` yet):
31+
전체 예시를 살펴봅시다. 아직 `fetch`는 사용하지 않습니다.
4232

4333
```js run
4434
let controller = new AbortController();
4535
let signal = controller.signal;
4636

47-
<<<<<<< HEAD
48-
// The party that performs a cancelable operation
49-
// gets "signal" object
50-
=======
51-
// The party that performs a cancelable operation
52-
// gets the "signal" object
53-
>>>>>>> upstream/master
54-
// and sets the listener to trigger when controller.abort() is called
55-
signal.addEventListener('abort', () => alert("abort!"));
37+
// 취소 가능한 작업을 수행하는 쪽은
38+
// "signal" 객체를 받고,
39+
// controller.abort()가 호출되었을 때 실행될 리스너를 설정합니다.
40+
signal.addEventListener('abort', () => alert("중단!"));
5641

57-
// The other party, that cancels (at any point later):
58-
controller.abort(); // abort!
42+
// 취소하는 쪽은 나중에 언제든 다음을 호출합니다.
43+
controller.abort(); // 중단!
5944

60-
// The event triggers and signal.aborted becomes true
45+
// 이벤트가 발생하고 signal.aborted가 true가 됩니다.
6146
alert(signal.aborted); // true
6247
```
6348

64-
<<<<<<< HEAD
65-
As we can see, `AbortController` is just a means to pass `abort` events when `abort()` is called on it.
49+
예시에서 볼 수 있듯이 `AbortController``abort()`가 호출되었을 때 `abort` 이벤트를 전달하는 수단입니다.
6650

67-
We could implement same kind of event listening in our code on our own, without `AbortController` object at all.
51+
`AbortController` 객체 없이도 코드에서 이런 이벤트 리스닝 방식을 직접 구현할 수 있습니다.
6852

69-
But what's valuable is that `fetch` knows how to work with `AbortController` object, it's integrated with it.
53+
하지만 중요한 점은 `fetch``AbortController` 객체와 함께 동작하는 방법을 알고 있다는 것입니다. `fetch``AbortController`는 통합되어 있습니다.
7054

71-
## Using with fetch
55+
## fetch와 함께 사용하기
7256

73-
To become able to cancel `fetch`, pass the `signal` property of an `AbortController` as a `fetch` option:
74-
=======
75-
As we can see, `AbortController` is just a mean to pass `abort` events when `abort()` is called on it.
76-
77-
We could implement the same kind of event listening in our code on our own, without the `AbortController` object.
78-
79-
But what's valuable is that `fetch` knows how to work with the `AbortController` object. It's integrated in it.
80-
81-
## Using with fetch
82-
83-
To be able to cancel `fetch`, pass the `signal` property of an `AbortController` as a `fetch` option:
84-
>>>>>>> upstream/master
57+
`fetch`를 취소할 수 있게 하려면 `AbortController``signal` 프로퍼티를 `fetch` 옵션으로 넘기면 됩니다.
8558

8659
```js
8760
let controller = new AbortController();
@@ -90,26 +63,22 @@ fetch(url, {
9063
});
9164
```
9265

93-
The `fetch` method knows how to work with `AbortController`. It will listen to `abort` events on `signal`.
66+
`fetch` 메서드는 `AbortController`와 함께 동작하는 방법을 알고 있습니다. `fetch``signal``abort` 이벤트를 감지합니다.
9467

95-
<<<<<<< HEAD
96-
Now, to to abort, call `controller.abort()`:
97-
=======
98-
Now, to abort, call `controller.abort()`:
99-
>>>>>>> upstream/master
68+
이제 중단하려면 `controller.abort()`를 호출하면 됩니다.
10069

10170
```js
10271
controller.abort();
10372
```
10473

105-
We're done: `fetch` gets the event from `signal` and aborts the request.
74+
이게 전부입니다. `fetch``signal`로부터 이벤트를 받아 요청을 중단합니다.
10675

107-
When a fetch is aborted, its promise rejects with an error `AbortError`, so we should handle it, e.g. in `try..catch`.
76+
`fetch`가 중단되면 해당 프라미스는 `AbortError` 에러와 함께 거부됩니다. 따라서 `try..catch` 등으로 이를 처리해야 합니다.
10877

109-
Here's the full example with `fetch` aborted after 1 second:
78+
다음은 1초 후 `fetch`를 중단하는 전체 예시입니다.
11079

11180
```js run async
112-
// abort in 1 second
81+
// 1초 후 중단
11382
let controller = new AbortController();
11483
setTimeout(() => controller.abort(), 1000);
11584

@@ -118,71 +87,62 @@ try {
11887
signal: controller.signal
11988
});
12089
} catch(err) {
121-
if (err.name == 'AbortError') { // handle abort()
122-
alert("Aborted!");
90+
if (err.name == 'AbortError') { // abort() 처리
91+
alert("중단되었습니다!");
12392
} else {
12493
throw err;
12594
}
12695
}
12796
```
12897

129-
## AbortController is scalable
98+
## AbortController는 확장성이 좋습니다
13099

131-
<<<<<<< HEAD
132-
`AbortController` is scalable, it allows to cancel multiple fetches at once.
133-
=======
134-
`AbortController` is scalable. It allows to cancel multiple fetches at once.
135-
>>>>>>> upstream/master
100+
`AbortController`는 확장성이 좋습니다. 여러 `fetch`를 한꺼번에 취소할 수 있습니다.
136101

137-
Here's a sketch of code that fetches many `urls` in parallel, and uses a single controller to abort them all:
102+
다음은 여러 `url`을 병렬로 가져오고, 하나의 컨트롤러로 모든 요청을 중단하는 코드 예시입니다.
138103

139104
```js
140-
let urls = [...]; // a list of urls to fetch in parallel
105+
let urls = [...]; // 병렬로 가져올 url 목록
141106

142107
let controller = new AbortController();
143108

144-
// an array of fetch promises
109+
// fetch 프라미스 배열
145110
let fetchJobs = urls.map(url => fetch(url, {
146111
signal: controller.signal
147112
}));
148113

149114
let results = await Promise.all(fetchJobs);
150115

151-
// if controller.abort() is called from anywhere,
152-
// it aborts all fetches
116+
// 어디서든 controller.abort()가 호출되면
117+
// 모든 fetch가 중단됩니다.
153118
```
154119

155-
If we have our own asynchronous tasks, different from `fetch`, we can use a single `AbortController` to stop those, together with fetches.
120+
`fetch`와는 다른 자체 비동기 작업이 있다면 하나의 `AbortController`를 사용해 해당 작업과 `fetch`를 함께 멈출 수 있습니다.
156121

157-
We just need to listen to its `abort` event in our tasks:
122+
작업 안에서 `abort` 이벤트를 감지하기만 하면 됩니다.
158123

159124
```js
160125
let urls = [...];
161126
let controller = new AbortController();
162127

163-
let ourJob = new Promise((resolve, reject) => { // our task
128+
let ourJob = new Promise((resolve, reject) => { // 자체 작업
164129
...
165130
controller.signal.addEventListener('abort', reject);
166131
});
167132

168-
let fetchJobs = urls.map(url => fetch(url, { // fetches
133+
let fetchJobs = urls.map(url => fetch(url, { // fetch 작업들
169134
signal: controller.signal
170135
}));
171136

172-
// Wait for fetches and our task in parallel
137+
// fetch 작업과 자체 작업을 병렬로 기다립니다.
173138
let results = await Promise.all([...fetchJobs, ourJob]);
174139

175-
// if controller.abort() is called from anywhere,
176-
// it aborts all fetches and ourJob
140+
// 어디서든 controller.abort()가 호출되면
141+
// 모든 fetch와 ourJob이 중단됩니다.
177142
```
178143

179-
## Summary
144+
## 요약
180145

181-
<<<<<<< HEAD
182-
- `AbortController` is a simple object that generates `abort` event on it's `signal` property when `abort()` method is called (and also sets `signal.aborted` to `true`).
183-
- `fetch` integrates with it: we pass `signal` property as the option, and then `fetch` listens to it, so it becomes possible to abort the `fetch`.
184-
=======
185-
- `AbortController` is a simple object that generates an `abort` event on its `signal` property when the `abort()` method is called (and also sets `signal.aborted` to `true`).
186-
- `fetch` integrates with it: we pass the `signal` property as the option, and then `fetch` listens to it, so it's possible to abort the `fetch`.
187-
>>>>>>> upstream/master
188-
- We can use `AbortController` in our code. The "call `abort()`" -> "listen to `abort` event" interaction is simple and universal. We can use it even without `fetch`.
146+
- `AbortController``abort()` 메서드가 호출되면 `signal` 프로퍼티에서 `abort` 이벤트를 발생시키는 단순한 객체입니다. 이때 `signal.aborted``true`로 설정됩니다.
147+
- `fetch``AbortController`와 통합되어 있습니다. `signal` 프로퍼티를 옵션으로 넘기면 `fetch`가 이를 감지하므로 `fetch`를 중단할 수 있습니다.
148+
- `AbortController`는 일반 코드에서도 사용할 수 있습니다. `abort()` 호출과 `abort` 이벤트 감지로 이어지는 상호작용은 단순하고 범용적입니다. `fetch` 없이도 사용할 수 있습니다.

0 commit comments

Comments
 (0)