diff --git a/frontend/docs/lib/generated/snips/typescript/cancellations/workflow.ts b/frontend/docs/lib/generated/snips/typescript/cancellations/workflow.ts index 51d8eaa21..42f8d1e0e 100644 --- a/frontend/docs/lib/generated/snips/typescript/cancellations/workflow.ts +++ b/frontend/docs/lib/generated/snips/typescript/cancellations/workflow.ts @@ -2,7 +2,7 @@ import { Snippet } from '@/lib/generated/snips/types'; const snippet: Snippet = { "language": "typescript ", - "content": "import sleep from '@hatchet-dev/typescript-sdk/util/sleep';\nimport axios from 'axios';\nimport { hatchet } from '../hatchet-client';\n\n// > Declaring a Task\nexport const cancellation = hatchet.task({\n name: 'cancellation',\n fn: async (_, { cancelled }) => {\n await sleep(10 * 1000);\n\n if (cancelled) {\n throw new Error('Task was cancelled');\n }\n\n return {\n Completed: true,\n };\n },\n});\n\n// > Abort Signal\nexport const abortSignal = hatchet.task({\n name: 'abort-signal',\n fn: async (_, { abortController }) => {\n try {\n const response = await axios.get('https://api.example.com/data', {\n signal: abortController.signal,\n });\n // Handle the response\n } catch (error) {\n if (axios.isCancel(error)) {\n // Request was canceled\n console.log('Request canceled');\n } else {\n // Handle other errors\n }\n }\n },\n});\n\n// see ./worker.ts and ./run.ts for how to run the workflow\n", + "content": "import sleep from '@hatchet-dev/typescript-sdk/util/sleep';\nimport axios from 'axios';\nimport { hatchet } from '../hatchet-client';\n\n// > Declaring a Task\nexport const cancellation = hatchet.task({\n name: 'cancellation',\n fn: async (_, ctx) => {\n await sleep(10 * 1000);\n\n if (ctx.cancelled) {\n throw new Error('Task was cancelled');\n }\n\n return {\n Completed: true,\n };\n },\n});\n\n// > Abort Signal\nexport const abortSignal = hatchet.task({\n name: 'abort-signal',\n fn: async (_, { abortController }) => {\n try {\n const response = await axios.get('https://api.example.com/data', {\n signal: abortController.signal,\n });\n // Handle the response\n } catch (error) {\n if (axios.isCancel(error)) {\n // Request was canceled\n console.log('Request canceled');\n } else {\n // Handle other errors\n }\n }\n },\n});\n\n// see ./worker.ts and ./run.ts for how to run the workflow\n", "source": "out/typescript/cancellations/workflow.ts", "blocks": { "declaring_a_task": { diff --git a/sdks/typescript/src/v1/examples/cancellations/workflow.ts b/sdks/typescript/src/v1/examples/cancellations/workflow.ts index 5852e5b70..8789f5820 100644 --- a/sdks/typescript/src/v1/examples/cancellations/workflow.ts +++ b/sdks/typescript/src/v1/examples/cancellations/workflow.ts @@ -5,10 +5,10 @@ import { hatchet } from '../hatchet-client'; // > Declaring a Task export const cancellation = hatchet.task({ name: 'cancellation', - fn: async (_, { cancelled }) => { + fn: async (_, ctx) => { await sleep(10 * 1000); - if (cancelled) { + if (ctx.cancelled) { throw new Error('Task was cancelled'); }