From e14827e0c76ff8691b69eaf2d0c1d8a64ee0754a Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Sun, 13 Nov 2022 11:05:47 -0800 Subject: [PATCH] docs: add aborting procs --- .../3.tips/3.aborting-procedures.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/content/1.get-started/3.tips/3.aborting-procedures.md diff --git a/docs/content/1.get-started/3.tips/3.aborting-procedures.md b/docs/content/1.get-started/3.tips/3.aborting-procedures.md new file mode 100644 index 0000000..bec123e --- /dev/null +++ b/docs/content/1.get-started/3.tips/3.aborting-procedures.md @@ -0,0 +1,24 @@ +--- +title: Aborting Procedures +--- + +# Aborting Procedures + +tRPC adheres to the industry standard when it comes to aborting procedures. All you have to do is pass an `AbortSignal` to the query-options and then call its parent `AbortController`'s `abort` method. + +```ts [composables/useGetTodo.ts] +export default function useGetTodo(id: number) { + const { $client } = useNuxtApp() + const ac = new AbortController() + + onScopeDispose(() => { + ac.abort() + }) + + return useAsyncData(() => { + return $client.todo.getTodo.query(id, { + signal: ac.signal + }) + }) +} +```