Skip to content

Commit 4064da6

Browse files
authored
Refactor: Move sleep function to shared module and import it (#1700)
1 parent 30dd163 commit 4064da6

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

extensions/ql-vscode/src/pure/time.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ function createFormatter(unit: string) {
8787
unitDisplay: 'long'
8888
});
8989
}
90+
91+
export async function sleep(ms: number) {
92+
return new Promise(resolve => setTimeout(resolve, ms));
93+
}

extensions/ql-vscode/src/remote-queries/remote-queries-monitor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import { Credentials } from '../authentication';
33
import { Logger } from '../logging';
4+
import { sleep } from '../pure/time';
45
import { getWorkflowStatus, isArtifactAvailable, RESULT_INDEX_ARTIFACT_NAME } from './gh-api/gh-actions-api-client';
56
import { RemoteQuery } from './remote-query';
67
import { RemoteQueryWorkflowResult } from './remote-query-workflow-result';
@@ -30,7 +31,7 @@ export class RemoteQueriesMonitor {
3031
let attemptCount = 0;
3132

3233
while (attemptCount <= RemoteQueriesMonitor.maxAttemptCount) {
33-
await this.sleep(RemoteQueriesMonitor.sleepTime);
34+
await sleep(RemoteQueriesMonitor.sleepTime);
3435

3536
if (cancellationToken && cancellationToken.isCancellationRequested) {
3637
return { status: 'Cancelled' };
@@ -70,10 +71,6 @@ export class RemoteQueriesMonitor {
7071
void this.logger.log('Variant analysis monitoring timed out after 2 days');
7172
return { status: 'Cancelled' };
7273
}
73-
74-
private async sleep(ms: number) {
75-
return new Promise(resolve => setTimeout(resolve, ms));
76-
}
7774
}
7875

7976

extensions/ql-vscode/src/remote-queries/variant-analysis-monitor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { VariantAnalysisMonitorResult } from './shared/variant-analysis-monitor-result';
1111
import { processUpdatedVariantAnalysis } from './variant-analysis-processor';
1212
import { DisposableObject } from '../pure/disposable-object';
13+
import { sleep } from '../pure/time';
1314

1415
export class VariantAnalysisMonitor extends DisposableObject {
1516
// With a sleep of 5 seconds, the maximum number of attempts takes
@@ -40,7 +41,7 @@ export class VariantAnalysisMonitor extends DisposableObject {
4041
const scannedReposDownloaded: number[] = [];
4142

4243
while (attemptCount <= VariantAnalysisMonitor.maxAttemptCount) {
43-
await this.sleep(VariantAnalysisMonitor.sleepTime);
44+
await sleep(VariantAnalysisMonitor.sleepTime);
4445

4546
if (cancellationToken && cancellationToken.isCancellationRequested) {
4647
return { status: 'Canceled' };
@@ -108,8 +109,4 @@ export class VariantAnalysisMonitor extends DisposableObject {
108109

109110
return downloadedRepos;
110111
}
111-
112-
private async sleep(ms: number) {
113-
return new Promise(resolve => setTimeout(resolve, ms));
114-
}
115112
}

extensions/ql-vscode/src/vscode-tests/no-workspace/query-results.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { slurpQueryHistory, splatQueryHistory } from '../../query-serialization'
1313
import { formatLegacyMessage, QueryInProgress } from '../../legacy-query-server/run-queries';
1414
import { EvaluationResult, QueryResultType } from '../../pure/legacy-messages';
1515
import Sinon = require('sinon');
16+
import { sleep } from '../../pure/time';
1617

1718
describe('query-results', () => {
1819
let disposeSpy: sinon.SinonSpy;
@@ -455,10 +456,6 @@ describe('query-results', () => {
455456
}
456457
}
457458

458-
async function sleep(ms: number) {
459-
return new Promise(resolve => setTimeout(resolve, ms));
460-
}
461-
462459
function createMockQueryWithResults(
463460
queryPath: string,
464461
didRunSuccessfully = true,

0 commit comments

Comments
 (0)