MCPcopy Index your code
hub / github.com/bugy/script-server / stopAll

Function stopAll

web-src/src/main-app/store/scriptExecutionManager.js:162–197  ·  view source on GitHub ↗
({getters, dispatch})

Source from the content-addressed store, hash-verified

160 },
161
162 stopAll({getters, dispatch}) {
163 const activeExecutors = getters.activeExecutors;
164 if (isEmptyArray(activeExecutors)) {
165 return Promise.resolve();
166 }
167
168 return new Promise((resolve, reject) => {
169 let message;
170 if (activeExecutors.length === 1) {
171 message = 'Some script is running. Do you want to abort it?'
172 } else {
173 message = activeExecutors.length + ' scripts are running. Do you want to abort them?'
174 }
175
176 const abort = confirm(message);
177 if (abort === true) {
178 const abortPromises = activeExecutors.map(executor => dispatch(executor.state.id + '/abort'));
179 Promise.all(abortPromises)
180 .catch(error => console.log('Failed to stop an executor: ' + error))
181 .finally(() => {
182 let retries = 0;
183 const intervalId = setInterval(waitForStop, 50);
184
185 function waitForStop() {
186 if ((retries > 20) || (!getters.hasActiveExecutors)) {
187 resolve();
188 clearInterval(intervalId);
189 }
190 retries++;
191 }
192 });
193 } else {
194 reject();
195 }
196 });
197 },
198
199 selectExecutor({commit, state, dispatch}, executor) {
200 const currentExecutor = state.currentExecutor;

Callers

nothing calls this directly

Calls 3

isEmptyArrayFunction · 0.90
mapMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected