mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
Throw abort error if signal is pre-aborted
Respect pre-aborted AbortSignals immediately instead of attempting the operation first. This ensures callers that abort before invoking the retry function receive the expected rejection without unnecessary execution.
This commit is contained in:
@@ -45,6 +45,16 @@ describe('git index lock retry', () => {
|
||||
expect(run).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('rejects without running when the signal is already aborted', async () => {
|
||||
vi.useFakeTimers()
|
||||
const run = vi.fn<() => Promise<string>>().mockResolvedValue('ok')
|
||||
|
||||
await expect(runWithGitIndexLockRetry(run, AbortSignal.abort())).rejects.toMatchObject({
|
||||
name: 'AbortError'
|
||||
})
|
||||
expect(run).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cancels a pending retry when the caller aborts', async () => {
|
||||
vi.useFakeTimers()
|
||||
const controller = new AbortController()
|
||||
|
||||
@@ -51,6 +51,9 @@ export async function runWithGitIndexLockRetry<T>(
|
||||
signal?: AbortSignal
|
||||
): Promise<T> {
|
||||
for (let attempt = 0; ; attempt += 1) {
|
||||
if (signal?.aborted) {
|
||||
throw createAbortError()
|
||||
}
|
||||
try {
|
||||
return await run()
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user