-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(workflow): Don't propagate cancellation from non-cancellable scop…
- Loading branch information
Showing
23 changed files
with
928 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getActivator } from '@temporalio/workflow/lib/global-attributes'; | ||
import { SdkFlag } from '@temporalio/workflow/lib/flags'; | ||
|
||
const defaultValueOverrides = new Map<number, boolean>(); | ||
|
||
let mockInstalled = false; | ||
|
||
function maybeInstallMock() { | ||
if (mockInstalled) return; | ||
const activator = getActivator(); | ||
const originalHasFlag = activator.hasFlag.bind(activator); | ||
activator.hasFlag = (flag) => { | ||
const overridenDefaultValue = defaultValueOverrides.get(flag.id); | ||
if (overridenDefaultValue !== undefined) { | ||
flag = { id: flag.id, default: overridenDefaultValue }; | ||
} | ||
return originalHasFlag(flag); | ||
}; | ||
mockInstalled = true; | ||
} | ||
|
||
// Override the default value of an SDK flag. That is, assuming a workflow execution is not in | ||
// replay mode and that `f` has not already been recorded, then `hasFlag(f)` will return | ||
// `defaultValue`, and record the flag to history if `defaultValue` is `true`. | ||
export function overrideSdkInternalFlag(flag: SdkFlag, defaultValue: boolean): void { | ||
maybeInstallMock(); | ||
defaultValueOverrides.set(flag.id, defaultValue); | ||
} |
Oops, something went wrong.