Aborting Procedure Calls
tRPC adheres to the industry standard when it comes to aborting procedures. All you have to do is pass an AbortSignal
to the query or mutation options, and call the AbortController
instance's abort
method if you need to cancel the request.
utils.tsts
// @filename: server.tsimport {createTRPCProxyClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from 'server.ts';constproxy =createTRPCProxyClient <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 {createTRPCProxyClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from 'server.ts';constproxy =createTRPCProxyClient <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 ();