Skip to content

Commit cd9e7fc

Browse files
ambirdsallAlex Birdsall
authored andcommitted
Put interval and maxTimeout inside options arg
1 parent 4dcbeec commit cd9e7fc

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

airbyte-webapp/src/core/request/pollUntil.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ describe("pollUntil", () => {
1313
it("calls the provided apiFn until condition returns true and resolves to its final return value", () => {
1414
const pollableFn = fourZerosAndThenSeven();
1515

16-
return expect(pollUntil(pollableFn, truthyResponse, 1)).resolves.toBe(7);
16+
return expect(pollUntil(pollableFn, truthyResponse, { interval: 1 })).resolves.toBe(7);
1717
});
1818
});
1919

2020
describe("when condition returns true before maxTimeout is reached", () => {
2121
it("calls the provided apiFn until condition returns true and resolves to its final return value", () => {
2222
const pollableFn = fourZerosAndThenSeven();
2323

24-
return expect(pollUntil(pollableFn, truthyResponse, 1, 100)).resolves.toBe(7);
24+
return expect(pollUntil(pollableFn, truthyResponse, { interval: 1, maxTimeout: 100 })).resolves.toBe(7);
2525
});
2626
});
2727

2828
describe("when maxTimeout is reached before condition returns true", () => {
2929
it("resolves to false", () => {
3030
const pollableFn = fourZerosAndThenSeven();
3131

32-
return expect(pollUntil(pollableFn, truthyResponse, 100, 1)).resolves.toBe(false);
32+
return expect(pollUntil(pollableFn, truthyResponse, { interval: 100, maxTimeout: 1 })).resolves.toBe(false);
3333
});
3434

3535
// Because the timing of the polling depends on both the provided `interval` and the
@@ -46,7 +46,7 @@ describe("pollUntil", () => {
4646
return val;
4747
});
4848

49-
await pollUntil(pollableFn, (_) => false, 20, 78);
49+
await pollUntil(pollableFn, (_) => false, { interval: 20, maxTimeout: 78 });
5050

5151
// In theory, this is what just happened:
5252
// | time elapsed | value (source) |

airbyte-webapp/src/core/request/pollUntil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { timer, delay, from, concatMap, takeWhile, last, raceWith, lastValueFrom
55
export function pollUntil<ResponseType>(
66
apiFn: () => Promise<ResponseType>,
77
condition: (res: ResponseType) => boolean,
8-
interval: number,
9-
maxTimeout?: number
8+
options: { interval: number; maxTimeout?: number }
109
) {
10+
const { interval, maxTimeout } = options;
1111
const poll$ = timer(0, interval).pipe(
1212
concatMap((_) => from(apiFn())),
1313
takeWhile((result) => !condition(result), true),

airbyte-webapp/src/packages/cloud/components/experiments/FreeConnectorProgram/hooks/useFreeConnectorProgram.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ export const useFreeConnectorProgram = () => {
4040
pollUntil(
4141
() => webBackendGetFreeConnectorProgramInfoForWorkspace({ workspaceId }, requestOptions),
4242
({ hasPaymentAccountSaved }) => hasPaymentAccountSaved,
43-
1000,
44-
10000
43+
{ interval: 1000, maxTimeout: 10000 }
4544
).then((maybeFcpInfo) => {
4645
if (maybeFcpInfo) {
4746
setSearchParams({}, { replace: true });

0 commit comments

Comments
 (0)