Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96d99c4

Browse files
authored
feat(workflow)!: Change condition parameter order (temporalio#371)
1 parent 81eb0fb commit 96d99c4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/test/src/workflows/condition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function conditionWaiter(): Promise<void> {
1313
condition(() => x === 2),
1414
]);
1515

16-
if (await condition('1s', () => x === 3)) {
16+
if (await condition(() => x === 3, '1s')) {
1717
throw new Error('Condition returned true');
1818
}
1919

packages/workflow/src/workflow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,18 +840,18 @@ function patchInternal(patchId: string, deprecated: boolean): boolean {
840840
*
841841
* @returns a boolean indicating whether the condition was true before the timeout expires
842842
*/
843-
export function condition(timeout: number | string, fn: () => boolean): Promise<boolean>;
843+
export function condition(fn: () => boolean, timeout: number | string): Promise<boolean>;
844844

845845
/**
846846
* Returns a Promise that resolves when `fn` evaluates to `true`.
847847
*/
848848
export function condition(fn: () => boolean): Promise<void>;
849849

850-
export function condition(fnOrTimeout: (() => boolean) | number | string, fn?: () => boolean): Promise<void | boolean> {
851-
if ((typeof fnOrTimeout === 'number' || typeof fnOrTimeout === 'string') && fn !== undefined) {
852-
return Promise.race([sleep(fnOrTimeout).then(() => false), conditionInner(fn).then(() => true)]);
850+
export function condition(fn: () => boolean, timeout?: number | string): Promise<void | boolean> {
851+
if (timeout) {
852+
return Promise.race([sleep(timeout).then(() => false), conditionInner(fn).then(() => true)]);
853853
}
854-
return conditionInner(fnOrTimeout as () => boolean);
854+
return conditionInner(fn);
855855
}
856856

857857
function conditionInner(fn: () => boolean): Promise<void> {

0 commit comments

Comments
 (0)