中断过程调用
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
在中断过程调用方面,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 ();