プロシージャコールの中止
tRPC は、プロシージャの中止に関して業界標準に準拠しています。クエリまたはミューテーションオプションに AbortSignal
を渡して、リクエストをキャンセルする必要がある場合は `AbortController` インスタンスの `abort` メソッドを呼び出すだけです。
utils.tsts
// @filename: server.tsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from 'server.ts';constproxy =createTRPCClient <AppRouter >({links : [httpBatchLink ({url : 'http://localhost:3000/trpc',}),],});// 1. Create an AbortController instance - this is a standard javascript APIconstac = newAbortController ();// 2. Pass the signal to a query or mutationconstquery =proxy .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();
utils.tsts
// @filename: server.tsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from 'server.ts';constproxy =createTRPCClient <AppRouter >({links : [httpBatchLink ({url : 'http://localhost:3000/trpc',}),],});// 1. Create an AbortController instance - this is a standard javascript APIconstac = newAbortController ();// 2. Pass the signal to a query or mutationconstquery =proxy .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();