Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5389eab

Browse files
committed
Cancel Operations with a {cancel} callback
1 parent 37b8cbd commit 5389eab

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/worker-manager.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export default class WorkerManager {
4141
return this.activeWorker.executeOperation(operation);
4242
});
4343
operation.setPromise(requestPromise);
44-
return requestPromise;
44+
return {
45+
cancel: () => this.activeWorker.cancelOperation(operation),
46+
promise: requestPromise,
47+
};
4548
}
4649

4750
createNewWorker({operationCountLimit} = {operationCountLimit: 10}) {
@@ -154,6 +157,10 @@ export class Worker {
154157
return this.rendererProcess.executeOperation(operation);
155158
}
156159

160+
cancelOperation(operation) {
161+
return this.rendererProcess.cancelOperation(operation);
162+
}
163+
157164
@autobind
158165
handleDataReceived({id, results}) {
159166
const operation = this.operationsById.get(id);
@@ -324,6 +331,16 @@ export class RendererProcess {
324331
});
325332
}
326333

334+
cancelOperation(operation) {
335+
return operation.cancel(payload => {
336+
if (this.destroyed) { return null; }
337+
return this.webContents.send(Worker.channelName, {
338+
type: 'git-cancel',
339+
data: payload,
340+
});
341+
});
342+
}
343+
327344
getPid() {
328345
return this.pid;
329346
}
@@ -406,4 +423,8 @@ export class Operation {
406423
this.startTime = performance.now();
407424
return execFn({...this.data, id: this.id});
408425
}
426+
427+
cancel(execFn) {
428+
return execFn({id: this.id});
429+
}
409430
}

0 commit comments

Comments
 (0)