본문 바로가기
버전: 11.x

프로시저 호출 중단

비공식 베타 번역

이 페이지는 PageTurner AI로 번역되었습니다(베타). 프로젝트 공식 승인을 받지 않았습니다. 오류를 발견하셨나요? 문제 신고 →

tRPC는 프로시저 중단을 위해 표준 AbortController/AbortSignal API를 지원합니다. 쿼리나 뮤테이션 옵션에 AbortSignal을 전달하기만 하면 되며, 요청을 취소해야 할 때는 AbortController 인스턴스의 abort 메서드를 호출하면 됩니다.

utils.ts
ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';
 
const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000/trpc',
}),
],
});
 
// 1. Create an AbortController instance - this is a standard javascript API
const ac = new AbortController();
 
// 2. Pass the signal to a query or mutation
const query = client.userById.query('id_bilbo', { signal: ac.signal });
 
// 3. Cancel the request if needed
ac.abort();
utils.ts
ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';
 
const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000/trpc',
}),
],
});
 
// 1. Create an AbortController instance - this is a standard javascript API
const ac = new AbortController();
 
// 2. Pass the signal to a query or mutation
const query = client.userById.query('id_bilbo', { signal: ac.signal });
 
// 3. Cancel the request if needed
ac.abort();