中断过程调用
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
tRPC支持通过标准的AbortController/AbortSignal API中断过程调用。你只需将AbortSignal传递给查询或变更选项,并在需要取消请求时调用AbortController实例的abort方法即可。
utils.tstsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from './server';constclient =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 =client .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();
utils.tstsimport {createTRPCClient ,httpBatchLink } from '@trpc/client';import type {AppRouter } from './server';constclient =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 =client .userById .query ('id_bilbo', {signal :ac .signal });// 3. Cancel the request if neededac .abort ();