From c89375df9fefce06dccc7f93f03af6c3c65c01da Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:12:16 +0000 Subject: [PATCH] Linting fixes --- packages/cache/src/internal/downloadUtils.ts | 59 ++++++++++---------- packages/cache/src/options.ts | 6 +- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/packages/cache/src/internal/downloadUtils.ts b/packages/cache/src/internal/downloadUtils.ts index cccf2c0d..992ca787 100644 --- a/packages/cache/src/internal/downloadUtils.ts +++ b/packages/cache/src/internal/downloadUtils.ts @@ -12,7 +12,7 @@ import {SocketTimeout} from './constants' import {DownloadOptions} from '../options' import {retryHttpClientResponse} from './requestUtils' -import { AbortController } from "@azure/abort-controller"; +import {AbortController} from '@azure/abort-controller' /** * Pipes the body of a HTTP response to a stream @@ -249,8 +249,7 @@ export async function downloadCacheStorageSDK( try { downloadProgress.startDisplayTimer() - const controller = new AbortController(); - const abortSignal = controller.signal; + const controller = new AbortController() while (!downloadProgress.isDone()) { const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize @@ -261,24 +260,22 @@ export async function downloadCacheStorageSDK( ) downloadProgress.nextSegment(segmentSize) - const abortTimeInMs = options.abortTimeInMs == undefined ? 2700000 : options.abortTimeInMs; - const result = await promiseWithTimeout(abortTimeInMs, client.downloadToBuffer( - segmentStart, - segmentSize, - { - abortSignal: abortSignal, + const abortTimeInMs = + options.abortTimeInMs === undefined ? 2700000 : options.abortTimeInMs + const result = await promiseWithTimeout( + abortTimeInMs, + client.downloadToBuffer(segmentStart, segmentSize, { + abortSignal: controller.signal, concurrency: options.downloadConcurrency, onProgress: downloadProgress.onProgress() - } - )); - if(result === 'timeout') { - controller.abort(); - throw new Error("Download aborted, segment download timed out."); - } else { - core.debug("Download completely successfully, cancelling timer.") + }) + ) + if (result === 'timeout') { + controller.abort() + throw new Error('Download aborted, segment download timed out.') + } else if (Buffer.isBuffer(result)) { + fs.writeFileSync(fd, result) } - - fs.writeFileSync(fd, result) } } finally { downloadProgress.stopDisplayTimer() @@ -287,17 +284,17 @@ export async function downloadCacheStorageSDK( } } -const promiseWithTimeout = (timeoutMs: number, promise: Promise) => { - let timeoutHandle: NodeJS.Timeout; - const timeoutPromise = new Promise((resolve, reject) => { - timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs); - }); +const promiseWithTimeout = async ( + timeoutMs: number, + promise: Promise +): Promise => { + let timeoutHandle: NodeJS.Timeout + const timeoutPromise = new Promise(resolve => { + timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs) + }) - return Promise.race([ - promise, - timeoutPromise, - ]).then((result) => { - clearTimeout(timeoutHandle); - return result; - }); -} \ No newline at end of file + return Promise.race([promise, timeoutPromise]).then(result => { + clearTimeout(timeoutHandle) + return result + }) +} diff --git a/packages/cache/src/options.ts b/packages/cache/src/options.ts index bc0c03b7..7473cfe4 100644 --- a/packages/cache/src/options.ts +++ b/packages/cache/src/options.ts @@ -45,16 +45,14 @@ export interface DownloadOptions { * * @default 30000 */ - timeoutInMs?: number + timeoutInMs?: number - /** * Time after which download should be aborted if stuck * * @default 2700000 */ - abortTimeInMs?: number - + abortTimeInMs?: number } /**