Skip to content

Commit 305a8ba

Browse files
committed
chore: help infer the return type of retryKubernetesApiRequest()
We were using "any" as the default return type but we can use generics to help infer the expected response type automatically for us.
1 parent 8c7475f commit 305a8ba

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/supervisor/kuberenetes-api-wrappers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import * as sleep from 'sleep-promise';
44
export const ATTEMPTS_MAX = 3;
55
export const DEFAULT_SLEEP_SEC = 1;
66
export const MAX_SLEEP_SEC = 5;
7-
type IKubernetesApiFunction = () => Promise<any>;
8-
9-
export async function retryKubernetesApiRequest(func: IKubernetesApiFunction) {
7+
type IKubernetesApiFunction<ResponseType> = () => Promise<ResponseType>;
108

9+
export async function retryKubernetesApiRequest<ResponseType>(
10+
func: IKubernetesApiFunction<ResponseType>
11+
): Promise<ResponseType> {
1112
for (let attempt = 1; attempt <= ATTEMPTS_MAX; attempt++) {
1213
try {
1314
return await func();
@@ -29,6 +30,8 @@ export async function retryKubernetesApiRequest(func: IKubernetesApiFunction) {
2930
await sleep(sleepSeconds * 1000);
3031
}
3132
}
33+
34+
throw new Error('Could not receive a response from the Kubernetes API');
3235
}
3336

3437
export function calculateSleepSeconds(httpResponse: http.IncomingMessage): number {

0 commit comments

Comments
 (0)