Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if a task run is in progress before running it #165560

Merged
merged 2 commits into from Nov 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Expand Up @@ -218,6 +218,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer

protected _taskRunningState: IContextKey<boolean>;

private _inProgressTasks: Set<string> = new Set();

protected _outputChannel: IOutputChannel;
protected readonly _onDidStateChange: Emitter<ITaskEvent>;
private _waitForSupportedExecutions: Promise<void>;
Expand Down Expand Up @@ -1203,6 +1205,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if (!task) {
throw new TaskError(Severity.Info, nls.localize('TaskServer.noTask', 'Task to execute is undefined'), TaskErrors.TaskNotFound);
}
if (this._inProgressTasks.has(task._label)) {
this._logService.info('Prevented duplicate task from running', task._label);
return;
}
this._inProgressTasks.add(task._label);
const resolver = this._createResolver();
let executeTaskResult: ITaskSummary | undefined;
try {
Expand All @@ -1218,6 +1225,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
} catch (error) {
this._handleError(error);
return Promise.reject(error);
} finally {
this._inProgressTasks.delete(task._label);
}
}

Expand Down