You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`가 필요 없다고 판단한 경우처럼 말이죠.
5
5
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`뿐만 아니라 다른 비동기 작업도 중단할 수 있습니다.
7
7
8
-
The usage is very straightforward:
8
+
사용법은 아주 간단합니다.
9
9
10
-
## The AbortController object
10
+
## AbortController 객체
11
11
12
-
Create a controller:
12
+
컨트롤러를 하나 만듭니다.
13
13
14
14
```js
15
15
let controller =newAbortController();
16
16
```
17
17
18
-
A controller is an extremely simple object.
18
+
컨트롤러는 아주 단순한 객체입니다.
19
19
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.
let fetchJobs =urls.map(url=>fetch(url, { //fetches
133
+
let fetchJobs =urls.map(url=>fetch(url, { //fetch 작업들
169
134
signal:controller.signal
170
135
}));
171
136
172
-
//Wait for fetches and our task in parallel
137
+
//fetch 작업과 자체 작업을 병렬로 기다립니다.
173
138
let results =awaitPromise.all([...fetchJobs, ourJob]);
174
139
175
-
//if controller.abort() is called from anywhere,
176
-
//it aborts all fetches and ourJob
140
+
//어디서든 controller.abort()가 호출되면
141
+
//모든 fetch와 ourJob이 중단됩니다.
177
142
```
178
143
179
-
## Summary
144
+
## 요약
180
145
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