Skip to content

Commit 2dbe27e

Browse files
YunchuWangCopilot
andcommitted
docs/fix: address PR #293 review nits (result guard, whenAny example, @internal, createTimer @remarks)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b1232e5 commit 2dbe27e

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/durabletask-js/src/task/context/orchestration-context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ export abstract class OrchestrationContext {
108108
/**
109109
* Create a timer task that will fire at a specified time.
110110
*
111+
* @remarks
112+
* This abstract method is implemented only by the SDK's own orchestration
113+
* context (`RuntimeOrchestrationContext`); orchestrator code consumes a context
114+
* instance and does not subclass it. The return type is the concrete
115+
* {@link TimerTask} (which is a `Task`) so callers can cancel the timer — this
116+
* narrowing is safe for all callers.
117+
*
111118
* @param {Date | number} fireAt The time at which the timer should fire.
112119
* @returns {TimerTask} A cancellable Durable Timer task that schedules the timer to wake up the orchestrator
113120
*/

packages/durabletask-js/src/task/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class Task<T> {
5555
* Durable Functions `Task.result` shape.
5656
*/
5757
get result(): T | undefined {
58-
return this._isComplete ? this._result : undefined;
58+
return this._isComplete && !this._exception ? this._result : undefined;
5959
}
6060

6161
/**

packages/durabletask-js/src/task/timer-task.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import { CompletableTask } from "./completable-task";
1818
*
1919
* @example Cancel the loser of a race
2020
* ```typescript
21+
* import { whenAny } from "@microsoft/durabletask-js";
22+
*
2123
* const timeoutTask = context.createTimer(expirationDate);
2224
* const workTask = context.callActivity("DoWork");
23-
* const winner = yield context.whenAny([timeoutTask, workTask]);
25+
* const winner = yield whenAny([timeoutTask, workTask]);
2426
* if (winner === workTask && !timeoutTask.isCompleted) {
2527
* timeoutTask.cancel();
2628
* }
@@ -44,6 +46,8 @@ export class TimerTask extends CompletableTask<undefined> {
4446
* pending `CreateTimer` action and pending-task entry, so this class needs no
4547
* knowledge of the context's internals.
4648
*
49+
* @internal Invoked by the orchestration context when the timer is created.
50+
* Not part of the public `TimerTask` surface; orchestrator code must not call it.
4751
* @param handler - Called once, when {@link cancel} first transitions the timer
4852
* to the canceled state.
4953
*/

packages/durabletask-js/test/task.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ describe("Task (base class)", () => {
138138
expect(() => task.result).not.toThrow();
139139
expect(task.result).toBeUndefined();
140140
});
141+
142+
it("result returns undefined for a failed task even if _result was set", () => {
143+
const t = new CompletableTask<string>();
144+
t._result = "stale";
145+
t.fail("boom");
146+
expect(t.result).toBeUndefined();
147+
expect(t.isFaulted).toBe(true);
148+
});
141149
});
142150

143151
describe("isCompleted / isFaulted (v3 aliases)", () => {

0 commit comments

Comments
 (0)