formatting
This commit is contained in:
@@ -267,17 +267,18 @@ export class ExponentialBackoff {
|
|||||||
// Wait for the delay or the abort signal
|
// Wait for the delay or the abort signal
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
// Set a timeout to resolve the promise after the delay
|
// Set a timeout to resolve the promise after the delay
|
||||||
|
// eslint-disable-next-line prefer-const
|
||||||
let timeout: ReturnType<typeof setTimeout>;
|
let timeout: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
// Handle the abort signal
|
// Handle the abort signal
|
||||||
const abortHandler = () => {
|
const abortHandler = (): void => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
abortController.signal.removeEventListener('abort', abortHandler);
|
abortController.signal.removeEventListener('abort', abortHandler);
|
||||||
reject(new ExponentialBackoffStoppedRetriesError(abortController.signal.reason));
|
reject(new ExponentialBackoffStoppedRetriesError(abortController.signal.reason));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the timeout
|
// Handle the timeout
|
||||||
const timeoutHandler = () => {
|
const timeoutHandler = (): void => {
|
||||||
abortController.signal.removeEventListener('abort', abortHandler);
|
abortController.signal.removeEventListener('abort', abortHandler);
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
};
|
};
|
||||||
@@ -287,7 +288,7 @@ export class ExponentialBackoff {
|
|||||||
|
|
||||||
// Add the abort handler to the abort signal
|
// Add the abort handler to the abort signal
|
||||||
abortController.signal.addEventListener('abort', abortHandler);
|
abortController.signal.addEventListener('abort', abortHandler);
|
||||||
})
|
});
|
||||||
|
|
||||||
attempt++;
|
attempt++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,8 +328,7 @@ const testExponentialBackoffRunDelayAbortedWhenAbortSignal = async (): Promise<v
|
|||||||
throw new Error('abort is not defined');
|
throw new Error('abort is not defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the rsult is still pending
|
// Check that the abort function is defined
|
||||||
expect(result).not.resolves;
|
|
||||||
expect(abort).toBeDefined();
|
expect(abort).toBeDefined();
|
||||||
|
|
||||||
// Abort the exponential backoff
|
// Abort the exponential backoff
|
||||||
@@ -337,11 +336,11 @@ const testExponentialBackoffRunDelayAbortedWhenAbortSignal = async (): Promise<v
|
|||||||
|
|
||||||
// Expect the result to be rejected with an ExponentialBackoffStoppedRetriesError
|
// Expect the result to be rejected with an ExponentialBackoffStoppedRetriesError
|
||||||
await expect(result).rejects.toThrow(ExponentialBackoffStoppedRetriesError);
|
await expect(result).rejects.toThrow(ExponentialBackoffStoppedRetriesError);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link ExponentialBackoff.from} factory and subsequent instance {@link ExponentialBackoff.run}
|
* Tests the {@link ExponentialBackoff.from} factory and subsequent instance {@link ExponentialBackoff.run}
|
||||||
* as an alternative to the static helper.
|
* as an alternative to the static helper.
|
||||||
@@ -629,7 +628,6 @@ const testExponentialBackoffValidateOptionsRejectsNaN = (): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Tests that passing undefined into the constructor does not cause an error during spread */
|
/** Tests that passing undefined into the constructor does not cause an error during spread */
|
||||||
const testExponentialBackoffConstructorDoesNotCauseErrorDuringSpread = async (): Promise<void> => {
|
const testExponentialBackoffConstructorDoesNotCauseErrorDuringSpread = async (): Promise<void> => {
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
Reference in New Issue
Block a user