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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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.
우리가 알고 있듯이, `fetch`는 프로미스를 반환합니다. 보통 자바스크립트에는 프로미스를 “중단하는” 개념은 없습니다. 그렇다면 진행 중인 `fetch`를 어떻게 취소할 수 있을까요? E.g) 만약 사이트에서 사용자 액션이`fetch`가 더 이상 필요하지 않다고 판단되는 경우
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.
이러한 경우를 위해 만들어진 특별한 객체가`AbortController` 입니다. `fetch`를 중단할 때 쓸 수 있을 뿐 아니라, 비동기 작업에도 쓸 수 있습니다.
The usage is very straightforward:
사용 방법은 간단합니다.
##TheAbortControllerobject
## AbortController객체
Create a controller:
컨트롤러를 생성합니다.
```js
let controller = new AbortController();
```
A controller is an extremely simple object.
컨트롤러는 아주 단순한 객체입니다.
-It has a single method`abort()`,
-And a single property`signal`that allows to set event liseners on it.
- `abort()` 라는 한가지 메소드를 가지고 있습니다.
-그리고`signal`라는 한 가지 프로퍼티를 가지며, 이 프로퍼티로 이벤트 리스너를 설정할 수 있습니다.
let results = await Promise.all([...fetchJobs, ourJob]);
//if controller.abort()is called from elsewhere,
//it aborts all fetches and ourJob
//만일 controller.abort()가 다른 곳에서 호출되면,
//모든 fetch와 작업이 중단됩니다.
```
##Summary
##요약
- `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`).
- `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`.
-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`.
- `AbortController`는`abort()` 메소드가 호출될 때 `signal`프로퍼티에`abort`이벤트를 생성하는(또한`signal.aborted`를 `true` 바꾸는) 단순한 객체입니다.
- `fetch`와 합칠 수 있습니다. 옵션으로 `signal`프로퍼티를 전달하면`fetch`는 이를 듣고, `fetch`를 중단할 수 있게 됩니다.
-코드에`AbortController`를 쓸 수 있습니다. "`abort()` 호출”-> "`abort`이벤트 듣기" 상호작용은 단순하며 범용적입니다. `fetch` 없이도 쓸 수 있습니다.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.