1
0
Fork 0

Added abort controller for timer

pull/1140/head
Sankalp Kotewar 2022-08-03 11:11:30 +00:00
parent e5e69a3171
commit 970264135a
1 changed files with 5 additions and 2 deletions

View File

@ -251,6 +251,7 @@ export async function downloadCacheStorageSDK(
try { try {
downloadProgress.startDisplayTimer() downloadProgress.startDisplayTimer()
const controller = new AbortController(); const controller = new AbortController();
const timerController = new AbortController();
const abortSignal = controller.signal; const abortSignal = controller.signal;
while (!downloadProgress.isDone()) { while (!downloadProgress.isDone()) {
const segmentStart = const segmentStart =
@ -262,7 +263,6 @@ export async function downloadCacheStorageSDK(
) )
downloadProgress.nextSegment(segmentSize) downloadProgress.nextSegment(segmentSize)
const result = await Promise.race([client.downloadToBuffer( const result = await Promise.race([client.downloadToBuffer(
segmentStart, segmentStart,
segmentSize, segmentSize,
@ -272,11 +272,14 @@ export async function downloadCacheStorageSDK(
onProgress: downloadProgress.onProgress() onProgress: downloadProgress.onProgress()
} }
), ),
timer.setTimeout(options.abortTimeInMs, 'timeout')]); timer.setTimeout(options.abortTimeInMs, 'timeout',{ signal: timerController.signal })]);
if(result === 'timeout') { if(result === 'timeout') {
controller.abort(); controller.abort();
throw new Error("Download aborted, segment download timed out."); throw new Error("Download aborted, segment download timed out.");
} else {
timerController.abort();
core.debug("Download completely successfully, cancelling timer.")
} }
fs.writeFileSync(fd, result) fs.writeFileSync(fd, result)