Skip to content

Commit b579db5

Browse files
committed
Clean delayed cmd queue on user request
1 parent 82688f0 commit b579db5

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/proc.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,34 @@ export function extendOSEnvironPath(name, items, prepend = true) {
9494
});
9595
}
9696

97+
/**
98+
* Run command helpers
99+
*/
100+
97101
const __RUN_CMD_QUEUE = [];
98102

103+
export function cleanCmdQueue() {
104+
while (__RUN_CMD_QUEUE.length) {
105+
const callback = __RUN_CMD_QUEUE.pop()[2];
106+
if (callback) {
107+
callback(-1, undefined, new Error('Terminated by user'));
108+
}
109+
}
110+
}
111+
112+
function _removeComletedCmdfromQueue(id) {
113+
const index = __RUN_CMD_QUEUE.findIndex((item) => item[3]._id === id);
114+
if (index > -1) {
115+
__RUN_CMD_QUEUE.splice(index, 1);
116+
}
117+
}
118+
119+
function _runNextCmdFromQueue() {
120+
if (__RUN_CMD_QUEUE.length > 0) {
121+
_runCommand(...__RUN_CMD_QUEUE.pop());
122+
}
123+
}
124+
99125
export function runCommand(cmd, args, callback = undefined, options = {}) {
100126
options = options || {};
101127
options.spawnOptions = options.spawnOptions || {};
@@ -171,18 +197,9 @@ function _runCommand(cmd, args, callback, options) {
171197
}
172198
}
173199

174-
function _removeComletedCmdfromQueue(id) {
175-
const index = __RUN_CMD_QUEUE.findIndex((item) => item[3]._id === id);
176-
if (index > -1) {
177-
__RUN_CMD_QUEUE.splice(index, 1);
178-
}
179-
}
180-
181-
function _runNextCmdFromQueue() {
182-
if (__RUN_CMD_QUEUE.length > 0) {
183-
_runCommand(...__RUN_CMD_QUEUE.pop());
184-
}
185-
}
200+
/**
201+
* End run command helpers
202+
*/
186203

187204
export function getCommandOutput(cmd, args, options = {}) {
188205
return new Promise((resolve, reject) => {

src/project/indexer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* the root directory of this source tree.
77
*/
88

9+
import { cleanCmdQueue } from '../proc';
910
import path from 'path';
1011
import { runPIOCommand } from '../core';
1112

@@ -120,6 +121,7 @@ export default class ProjectIndexer {
120121
if (token) {
121122
token.onCancellationRequested(() => {
122123
logMessage('Configuration process has been terminated!', true);
124+
cleanCmdQueue();
123125
subprocess.kill();
124126
});
125127
}

0 commit comments

Comments
 (0)