Skip to content

Commit

Permalink
Wait for task execution properly (#2234)
Browse files Browse the repository at this point in the history
Fixes #2231
  • Loading branch information
karolz-ms authored Aug 11, 2020
1 parent ea1fc4f commit 0f6a94f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/utils/executeAsTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { addDockerSettingsToEnv } from './addDockerSettingsToEnv';

export async function executeAsTask(context: IActionContext, command: string, name: string, options: { addDockerEnv?: boolean, workspaceFolder?: vscode.WorkspaceFolder, cwd?: string, alwaysRunNew?: boolean }): Promise<vscode.TaskExecution> {
export async function executeAsTask(context: IActionContext, command: string, name: string, options: { addDockerEnv?: boolean, workspaceFolder?: vscode.WorkspaceFolder, cwd?: string, alwaysRunNew?: boolean }): Promise<void> {
let newEnv: NodeJS.ProcessEnv | undefined;
options = options ?? {};

Expand All @@ -34,5 +34,16 @@ export async function executeAsTask(context: IActionContext, command: string, na
task.definition.idRandomizer = Math.random();
}

return vscode.tasks.executeTask(task);
const taskExecution = await vscode.tasks.executeTask(task);

const taskEndPromise = new Promise<void>((resolve) => {
const disposable = vscode.tasks.onDidEndTaskProcess(e => {
if (e.execution === taskExecution) {
disposable.dispose();
resolve();
}
});
});

return taskEndPromise;
}

0 comments on commit 0f6a94f

Please sign in to comment.