Skip to content

Commit

Permalink
Fix task instance limit (#97011)
Browse files Browse the repository at this point in the history
Fixes #96999
  • Loading branch information
alexr00 committed May 5, 2020
1 parent d4b8ec9 commit 96b89dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export class TerminalTaskSystem implements ITaskSystem {
}

public run(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult {
task = task.clone(); // A small amount of task state is stored in the task (instance) and tasks passed in to run may have that set already.
const recentTaskKey = task.getRecentlyUsedKey() ?? '';
let validInstance = task.runOptions && task.runOptions.instanceLimit && this.instances[recentTaskKey] && this.instances[recentTaskKey].instances < task.runOptions.instanceLimit;
let instance = this.instances[recentTaskKey] ? this.instances[recentTaskKey].instances : 0;
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/contrib/tasks/common/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ export class CustomTask extends CommonTask {
}
}

public clone(): CustomTask {
return new CustomTask(this._id, this._source, this._label, this.type, this.command, this.hasDefinedMatchers, this.runOptions, this.configurationProperties);
}

public customizes(): KeyedTaskIdentifier | undefined {
if (this._source && this._source.customizes) {
return this._source.customizes;
Expand Down Expand Up @@ -874,6 +878,10 @@ export class ContributedTask extends CommonTask {
this.command = command;
}

public clone(): ContributedTask {
return new ContributedTask(this._id, this._source, this._label, this.type, this.defines, this.command, this.hasDefinedMatchers, this.runOptions, this.configurationProperties);
}

public getDefinition(): KeyedTaskIdentifier {
return this.defines;
}
Expand Down Expand Up @@ -938,6 +946,10 @@ export class InMemoryTask extends CommonTask {
this._source = source;
}

public clone(): InMemoryTask {
return new InMemoryTask(this._id, this._source, this._label, this.type, this.runOptions, this.configurationProperties);
}

public static is(value: any): value is InMemoryTask {
return value instanceof InMemoryTask;
}
Expand Down

0 comments on commit 96b89dd

Please sign in to comment.