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
알다시피 `fetch`는 프라미스를 반환합니다. 그리고 자바스크립트에는 일반적으로 프라미스 "중단"이라는 개념이 없습니다. 그렇다면 사이트에서 `fetch`가 더는 필요하지 않음을 나타내는 사용자 액션이 일어날 경우, 진행 중인 `fetch`를 어떻게 중단할 수 있을까요?
3
4
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.
5
+
이러한 경우를 위한 `AbortContoller`라고 하는 특별한 내장 객체가 있습니다. 이 객체는 `fetch`를 비롯한 다른 비동기 작업을 중단하는 데 사용할 수 있습니다.
5
6
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.
7
+
사용법은 매우 직관적입니다.
7
8
8
-
The usage is very straightforward:
9
+
## AbortController 객체
9
10
10
-
## The AbortController object
11
-
12
-
Create a controller:
11
+
컨트롤러를 생성합니다.
13
12
14
13
```js
15
14
let controller =newAbortController();
16
15
```
17
16
18
-
A controller is an extremely simple object.
17
+
컨트롤러는 매우 단순한 객체입니다.
18
+
19
+
- 단일 메서드인 `abort()`를 갖습니다.
20
+
-`abort`에 대한 이벤트 리스너를 설정할 수 있는 단일 속성 `signal`을 갖습니다.
19
21
20
-
- It has a single method `abort()`,
21
-
- And a single property `signal` that allows to set event liseners on it.
let results =awaitPromise.all([...fetchJobs, ourJob]);
139
141
140
-
//if controller.abort() is called from elsewhere,
141
-
//it aborts all fetches and ourJob
142
+
//어딘가 다른 곳에서 controller.abort()가 호출되면
143
+
//모든 fetch와 자체 태스크를 중단합니다
142
144
```
143
145
144
-
## Summary
146
+
## 요약
145
147
146
-
-`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`).
147
-
-`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`.
148
-
-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`.
148
+
-`AbortController`는 `abort ()` 메서드가 호출될 때 자신의 `signal`속성에 `abort` 이벤트를 발생시키는 단순한 객체입니다(또한 `signal.aborted`를 `true`로 설정).
149
+
-`fetch`와 통합: `signal`속성을 옵션으로 전달하면 `fetch`가 `abort` 이벤트를 수신하므로 `fetch`를 중단할 수 있습니다.
150
+
-코드에서 `AbortController`를 사용할 수 있습니다. "`abort()` 호출" -> "`abort`이벤트 수신" 인터랙션은 단순하고 보편적입니다. 심지어 `fetch` 없이도 사용할 수 있습니다.
0 commit comments