Skip to content

Commit

Permalink
Fix compile project concurrency
Browse files Browse the repository at this point in the history
Possible fix for #14

Signed-off-by: William Vinnicombe <william.vinnicombe@raspberrypi.com>
  • Loading branch information
will-v-pi committed Apr 26, 2024
1 parent b91d26a commit f304339
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/commands/compileProject.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { commands, tasks, window } from "vscode";
import { EventEmitter } from 'events';
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import Settings, { SettingsKey } from "../settings.mjs";
Expand Down Expand Up @@ -34,7 +35,25 @@ export default class CompileProjectCommand extends Command {

if (task) {
// Execute the task
var emitter = new EventEmitter();

// add callbacks for task completion
var end = tasks.onDidEndTaskProcess(e => {
emitter.emit("terminated", e.exitCode);
});
var end2 = tasks.onDidEndTask(e => {
emitter.emit("terminated", -1);
});

await tasks.executeTask(task);
var code = await new Promise<Number>((resolve, reject) => {
emitter.on("terminated", code => resolve(code));
});

// dispose of callbacks
end.dispose();
end2.dispose();
this._logger.debug("Task 'Compile Project' completed with code " + code);
} else {
// Task not found
this._logger.error("Task 'Compile Project' not found.");
Expand Down

0 comments on commit f304339

Please sign in to comment.