File tree Expand file tree Collapse file tree 5 files changed +40
-16
lines changed Expand file tree Collapse file tree 5 files changed +40
-16
lines changed Original file line number Diff line number Diff line change 13841384 "lodash.isempty" : " ^4.4.0" ,
13851385 "lodash.isequal" : " ^4.5.0" ,
13861386 "lodash.merge" : " ^4.6.2" ,
1387- "lodash.omit" : " ^4.5.0"
1387+ "lodash.omit" : " ^4.5.0" ,
1388+ "tree-kill" : " ^1.2.2"
13881389 },
13891390 "devDependencies" : {
13901391 "@types/chai" : " ^4.2.22" ,
Original file line number Diff line number Diff line change @@ -133,18 +133,26 @@ export class CliRunner extends Disposable implements ICli {
133133 )
134134 }
135135
136- public async stop ( ) {
136+ public stop ( ) {
137+ const stopped = new Promise < boolean > ( resolve => {
138+ if ( ! this . currentProcess ) {
139+ return resolve ( false )
140+ }
141+ const listener = this . dispose . track (
142+ this . currentProcess . onDidDispose ( disposed => {
143+ this . dispose . untrack ( listener )
144+ listener ?. dispose ( )
145+ this . pseudoTerminal . close ( )
146+ resolve ( disposed )
147+ } )
148+ )
149+ } )
150+
137151 try {
138152 this . currentProcess ?. dispose ( )
139- await this . currentProcess
140- return false
141- } catch {
142- const stopped = ! this . currentProcess || this . currentProcess . killed
143- if ( stopped ) {
144- this . pseudoTerminal . close ( )
145- }
146- return stopped
147- }
153+ } catch { }
154+
155+ return stopped
148156 }
149157
150158 public isExperimentRunning ( ) {
Original file line number Diff line number Diff line change 11import { ChildProcess } from 'child_process'
22import { Readable } from 'stream'
3+ import { Event , EventEmitter } from 'vscode'
34import { Disposable } from '@hediet/std/disposable'
45import execa from 'execa'
56import { Logger } from './common/logger'
@@ -16,7 +17,9 @@ interface ProcessResult {
1617 signal ?: string
1718}
1819
19- export type Process = RunningProcess & Promise < ProcessResult > & Disposable
20+ export type Process = RunningProcess &
21+ Promise < ProcessResult > &
22+ Disposable & { onDidDispose : Event < boolean > }
2023
2124export interface ProcessOptions {
2225 executable : string
@@ -39,10 +42,14 @@ export const createProcess = ({
3942 windowsHide : true
4043 } )
4144
45+ const disposed = new EventEmitter < boolean > ( )
46+
4247 return Object . assign ( process , {
4348 dispose : ( ) => {
44- process . kill ( 'SIGINT' )
45- }
49+ const kill = require ( 'tree-kill' )
50+ kill ( process . pid , 'SIGINT' , ( ) => disposed . fire ( true ) )
51+ } ,
52+ onDidDispose : disposed . event
4653 } )
4754}
4855
Original file line number Diff line number Diff line change @@ -56,8 +56,11 @@ suite('CLI Runner Test Suite', () => {
5656 true
5757 )
5858
59- const stopped = await cliRunner . stop ( )
60- expect ( stopped ) . to . be . true
59+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60+ const closeSpy = spy ( ( cliRunner as any ) . pseudoTerminal , 'close' )
61+
62+ await cliRunner . stop ( )
63+ expect ( closeSpy ) . to . be . calledOnce
6164
6265 await completed
6366
Original file line number Diff line number Diff line change @@ -13837,6 +13837,11 @@ tr46@~0.0.3:
1383713837 resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9"
1383813838 integrity sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk=
1383913839
13840+ tree-kill@^1.2.2:
13841+ version "1.2.2"
13842+ resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
13843+ integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
13844+
1384013845trim-trailing-lines@^1.0.0:
1384113846 version "1.1.4"
1384213847 resolved "https://registry.yarnpkg.com/trim-trailing-lines/-/trim-trailing-lines-1.1.4.tgz#bd4abbec7cc880462f10b2c8b5ce1d8d1ec7c2c0"
You can’t perform that action at this time.
0 commit comments