From b416a89b488e03fcc25143b4ed4481d74a9b466d Mon Sep 17 00:00:00 2001 From: Kristina Koeva Date: Fri, 5 Aug 2016 17:29:45 +0300 Subject: [PATCH] Use the new processService for destroying the live sync socket --- .../livesync/ios-device-livesync-service.ts | 20 +++---------------- lib/services/livesync/livesync-service.ts | 6 ++++-- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/services/livesync/ios-device-livesync-service.ts b/lib/services/livesync/ios-device-livesync-service.ts index 66a14356e0..42b2b90721 100644 --- a/lib/services/livesync/ios-device-livesync-service.ts +++ b/lib/services/livesync/ios-device-livesync-service.ts @@ -19,7 +19,8 @@ class IOSLiveSyncService implements IDeviceLiveSyncService { private $iOSDebugService: IDebugService, private $childProcess: IChildProcess, private $fs: IFileSystem, - private $liveSyncProvider: ILiveSyncProvider) { + private $liveSyncProvider: ILiveSyncProvider, + private $processService: IProcessService) { this.device = (_device); } @@ -137,7 +138,7 @@ class IOSLiveSyncService implements IDeviceLiveSyncService { } private attachEventHandlers(): void { - this.attachProcessExitHandlers(); + this.$processService.attachToProcessExitSignals(this, this.destroySocket); this.socket.on("close", (hadError: boolean) => { this.$logger.trace(`Socket closed, hadError is ${hadError}.`); @@ -184,21 +185,6 @@ class IOSLiveSyncService implements IDeviceLiveSyncService { }).future()(); } - private attachProcessExitHandlers(): void { - process.on("exit", (exitCode: number) => { - this.destroySocket(); - }); - - process.on("SIGTERM", () => { - this.destroySocket(); - }); - - process.on("SIGINT", () => { - this.destroySocket(); - return process.exit(); - }); - } - private destroySocket(): void { if(this.socket) { this.socket.destroy(); diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index b95cced5c4..7128278262 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -24,7 +24,8 @@ class LiveSyncService implements ILiveSyncService { private $options: IOptions, private $logger: ILogger, private $dispatcher: IFutureDispatcher, - private $hooksService: IHooksService) { } + private $hooksService: IHooksService, + private $processService: IProcessService) { } private ensureAndroidFrameworkVersion(platformData: IPlatformData): IFuture { // TODO: this can be moved inside command or canExecute function return (() => { @@ -130,7 +131,7 @@ class LiveSyncService implements ILiveSyncService { private partialSync(syncWorkingDirectory: string, onChangedActions: ((event: string, filePath: string, dispatcher: IFutureDispatcher) => void )[]): void { let that = this; - gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) { + let gazeWatcher = gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) { this.on('all', (event: string, filePath: string) => { fiberBootstrap.run(() => { that.$dispatcher.dispatch(() => (() => { @@ -147,6 +148,7 @@ class LiveSyncService implements ILiveSyncService { }); }); + this.$processService.attachToProcessExitSignals(this, gazeWatcher.close); this.$dispatcher.run(); } }