4848 *
4949 * 1. `await` on {@link Context.cancelled | `Context.current().cancelled`} or
5050 * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
51- * 1 . Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
51+ * 2 . Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
5252 * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
5353 *
5454 * ### Examples
7070 */
7171
7272import { AsyncLocalStorage } from 'node:async_hooks' ;
73- import { Logger , Duration , LogLevel , LogMetadata , MetricMeter , Priority } from '@temporalio/common' ;
73+ import {
74+ Logger ,
75+ Duration ,
76+ LogLevel ,
77+ LogMetadata ,
78+ MetricMeter ,
79+ Priority ,
80+ ActivityCancellationDetailsHolder ,
81+ ActivityCancellationDetails ,
82+ } from '@temporalio/common' ;
7483import { msToNumber } from '@temporalio/common/lib/time' ;
7584import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers' ;
7685
@@ -289,6 +298,11 @@ export class Context {
289298 */
290299 public readonly metricMeter : MetricMeter ;
291300
301+ /**
302+ * Holder object for activity cancellation details
303+ */
304+ public readonly cancellationDetails : ActivityCancellationDetailsHolder ;
305+
292306 /**
293307 * **Not** meant to instantiated by Activity code, used by the worker.
294308 *
@@ -300,14 +314,16 @@ export class Context {
300314 cancellationSignal : AbortSignal ,
301315 heartbeat : ( details ?: any ) => void ,
302316 log : Logger ,
303- metricMeter : MetricMeter
317+ metricMeter : MetricMeter ,
318+ details : ActivityCancellationDetailsHolder
304319 ) {
305320 this . info = info ;
306321 this . cancelled = cancelled ;
307322 this . cancellationSignal = cancellationSignal ;
308323 this . heartbeatFn = heartbeat ;
309324 this . log = log ;
310325 this . metricMeter = metricMeter ;
326+ this . cancellationDetails = details ;
311327 }
312328
313329 /**
@@ -427,6 +443,13 @@ export function cancelled(): Promise<never> {
427443 return Context . current ( ) . cancelled ;
428444}
429445
446+ /**
447+ * Returns the cancellation details for this activity, if any.
448+ */
449+ export function cancellationDetails ( ) : ActivityCancellationDetails | undefined {
450+ return Context . current ( ) . cancellationDetails . details ;
451+ }
452+
430453/**
431454 * Return an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to
432455 * react to Activity cancellation.
0 commit comments