fix: improve abort handling in spawnJSONLProcess

- Added immediate invocation of abort handler if the abort signal is already triggered, ensuring proper cleanup.
- Updated test to use setImmediate for aborting, allowing the generator to start processing before the abort is called, enhancing reliability.
This commit is contained in:
Shirone
2026-01-04 03:50:17 +01:00
parent ef06c13c1a
commit c6d94d4bf4
2 changed files with 12 additions and 4 deletions

View File

@@ -97,7 +97,12 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
}
childProcess.kill('SIGTERM');
};
abortController.signal.addEventListener('abort', abortHandler);
// Check if already aborted, if so call handler immediately
if (abortController.signal.aborted) {
abortHandler();
} else {
abortController.signal.addEventListener('abort', abortHandler);
}
}
// Helper to clean up abort listener