티스토리 뷰
api 요청 후 요청을 취소할 상황이 생길시...
api 호출 후 응답시간이 길 경우, response 너무 늦게와 의도치 않는 사이드 이펙트를 초래할 경우가 있다.
이럴 경우 api 호출을 중단 해야 하는데, 그런 상황에 사용하는것이
AbortController
이다.
https://developer.mozilla.org/ko/docs/Web/API/AbortController
AbortController - Web API | MDN
AbortController 인터페이스는 하나 이상의 웹 요청을 취소할 수 있게 해준다.
developer.mozilla.org
사용법
// AbortController 생성
const controller = new AbortController();
abortBtn.addEventListener('click', function() {
// api 요청을 abort 한다.
controller.abort();
});
function fetchApi() {
...
await axios
.get(apiUrl, {
signal: abortController.signal,
})
.then((response) => {
res = response
})
.catch((error) => {
throw error
});
}
abort()가 호출되면, fetch() promise는 AbortError으로 명명된 DOMException과 함께 reject된다!
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 394 decode string
- react ref reative
- 394. decode string js
- react glsl
- next.js import glsl
- leva
- vue react
- typescript gsls
- react vue
- react 3d
- 394. decode string javascript
- react 3d animation
- react three fiber leva
- react leva
- webpack glsl
- vue3
- ts glsl
- [leetcode] 394. decode string
- vue reactive
- Vue.js
- eslint
- [leetcode] 394. decode string js
- react fiber 3d
- react 3d 에니메이션
- three.js leva
- vue
- react 3d text
- react three fiber
- vue ref
- attempted import error: bvh_struct_definitions' is not exported from './gpu/bvhshaderglsl.js' (imported as 'bvhshaderglsl').
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함