Skip to content

Commit 1bbc180

Browse files
committed
Improvements to asking about a new job
Signed-off-by: worksofliam <[email protected]>
1 parent f93f310 commit 1bbc180

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export let Config: ConnectionStorage;
1414
export let osDetail: IBMiDetail;
1515
export let JobManager: SQLJobManager = new SQLJobManager();
1616

17-
1817
export async function onConnectOrServerInstall(): Promise<boolean> {
1918
const instance = getInstance();
2019

@@ -87,6 +86,17 @@ export async function askAboutNewJob(startup?: boolean): Promise<boolean> {
8786
const connection = instance.getConnection();
8887

8988
if (connection) {
89+
90+
// Wait for the job manager to finish creating jobs if one is not selected
91+
while (JobManager.getSelection() === undefined && JobManager.isCreatingJob()) {
92+
await new Promise(resolve => setTimeout(resolve, 100));
93+
}
94+
95+
// If a job is created or already selected, don't ask
96+
if (JobManager.getSelection()) {
97+
return true;
98+
}
99+
90100
const options = startup ? [`Yes`, `Always`, `No`, `Never`] : [`Yes`, `No`];
91101

92102
const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, ...options);

src/connection/manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class SQLJobManager {
1919
private totalJobs = 0;
2020
private jobs: JobInfo[] = [];
2121
selectedJob: number = NO_SELECTED_JOB;
22+
private creatingJobs: number = 0;
2223

2324
constructor() { }
2425

@@ -39,6 +40,7 @@ export class SQLJobManager {
3940
}));
4041

4142
try {
43+
this.creatingJobs += 1;
4244
await newJob.connect();
4345

4446
if (osDetail) {
@@ -59,10 +61,16 @@ export class SQLJobManager {
5961
this.selectedJob = this.jobs.length - 1;
6062
} catch (e: any) {
6163
throw e;
64+
} finally {
65+
this.creatingJobs -= 1;
6266
}
6367
}
6468
}
6569

70+
isCreatingJob() {
71+
return this.creatingJobs > 0;
72+
}
73+
6674
getRunningJobs() {
6775
return this.jobs.filter(info => [JobStatus.Ready, JobStatus.Busy].includes(info.job.getStatus()));
6876
}

0 commit comments

Comments
 (0)