@@ -41,7 +41,10 @@ export default class WorkerManager {
41
41
return this . activeWorker . executeOperation ( operation ) ;
42
42
} ) ;
43
43
operation . setPromise ( requestPromise ) ;
44
- return requestPromise ;
44
+ return {
45
+ cancel : ( ) => this . activeWorker . cancelOperation ( operation ) ,
46
+ promise : requestPromise ,
47
+ } ;
45
48
}
46
49
47
50
createNewWorker ( { operationCountLimit} = { operationCountLimit : 10 } ) {
@@ -154,6 +157,10 @@ export class Worker {
154
157
return this . rendererProcess . executeOperation ( operation ) ;
155
158
}
156
159
160
+ cancelOperation ( operation ) {
161
+ return this . rendererProcess . cancelOperation ( operation ) ;
162
+ }
163
+
157
164
@autobind
158
165
handleDataReceived ( { id, results} ) {
159
166
const operation = this . operationsById . get ( id ) ;
@@ -324,6 +331,16 @@ export class RendererProcess {
324
331
} ) ;
325
332
}
326
333
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
+
327
344
getPid ( ) {
328
345
return this . pid ;
329
346
}
@@ -406,4 +423,8 @@ export class Operation {
406
423
this . startTime = performance . now ( ) ;
407
424
return execFn ( { ...this . data , id : this . id } ) ;
408
425
}
426
+
427
+ cancel ( execFn ) {
428
+ return execFn ( { id : this . id } ) ;
429
+ }
409
430
}
0 commit comments