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
Copy file name to clipboardExpand all lines: posts/kr/cancellation.md
+90-2Lines changed: 90 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,66 @@ next_title: 'URL-인코딩 바디'
6
6
next_link: '/kr/docs/urlencoded'
7
7
---
8
8
9
-
*취소 토큰*을 이용해 요청을 취소할 수 있습니다.
9
+
## 요청 취소
10
10
11
-
> Axios의 취소 토큰 API는 중단된 [proposal-cancelable-promises](https://github.com/tc39/proposal-cancelable-promises)을 기반으로 하고 있습니다.
11
+
axios 호출에서 `timeout` 속성을 설정하면 **응답** 관련 타임아웃을 처리합니다.
12
+
13
+
몇가지 경우에 (예: 네트워크 연결을 사용할 수 없게 되는 경우 등) axios **연결**을 조기에 취소하는것이 유리합니다. 취소를 하지 않는 경우, axios호출이 부모 코드/스택이 타임아웃 될 때까지 대기할 수 있습니다 (서버 측 응용 프로그램의 경우 몇 분이 걸릴 수 있습니다)
14
+
15
+
axios 호출을 종료하려면 다음과 같은 방법을 사용할 수 있습니다:
16
+
-`signal`
17
+
-`cancelToken` (deprecated)
18
+
19
+
`timeout`과 취소 방법(예: `signal`)을 결합하면 **응답** 관련 타임아웃과 **연결** 관련 타임아웃을 모두 처리할 수 있습니다.
20
+
21
+
### `signal`: AbortController
22
+
23
+
Axios는 `v0.22.0` 부터 fetch API의 방식대로 요청을 취소하기 위해 [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)를 지원합니다:
24
+
25
+
```js
26
+
constcontroller=newAbortController();
27
+
28
+
axios.get('/foo/bar', {
29
+
signal:controller.signal
30
+
}).then(function(response) {
31
+
//...
32
+
});
33
+
// 요청 취소하기
34
+
controller.abort()
35
+
```
36
+
37
+
최신 [`AbortSignal.timeout()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout) API를 사용한 타임아웃 예 [nodejs 17.3+]:
0 commit comments