Skip to content

Commit f05fce6

Browse files
committed
Use the new processService for destroying the live sync socket
1 parent 517aef4 commit f05fce6

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

lib/services/livesync/ios-device-livesync-service.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
1919
private $iOSDebugService: IDebugService,
2020
private $childProcess: IChildProcess,
2121
private $fs: IFileSystem,
22-
private $liveSyncProvider: ILiveSyncProvider) {
22+
private $liveSyncProvider: ILiveSyncProvider,
23+
private $processService: IProcessService) {
2324
this.device = <Mobile.IiOSDevice>(_device);
2425
}
2526

@@ -137,7 +138,7 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
137138
}
138139

139140
private attachEventHandlers(): void {
140-
this.attachProcessExitHandlers();
141+
this.$processService.attachToProcessExitSignals(this, () => Future.fromResult(this.destroySocket()));
141142

142143
this.socket.on("close", (hadError: boolean) => {
143144
this.$logger.trace(`Socket closed, hadError is ${hadError}.`);
@@ -184,21 +185,6 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
184185
}).future<void>()();
185186
}
186187

187-
private attachProcessExitHandlers(): void {
188-
process.on("exit", (exitCode: number) => {
189-
this.destroySocket();
190-
});
191-
192-
process.on("SIGTERM", () => {
193-
this.destroySocket();
194-
});
195-
196-
process.on("SIGINT", () => {
197-
this.destroySocket();
198-
return process.exit();
199-
});
200-
}
201-
202188
private destroySocket(): void {
203189
if(this.socket) {
204190
this.socket.destroy();

lib/services/livesync/livesync-service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as helpers from "../../common/helpers";
33
import * as path from "path";
44
import * as semver from "semver";
55
import * as fiberBootstrap from "../../common/fiber-bootstrap";
6+
import Future = require("fibers/future");
67

78
let gaze = require("gaze");
89

@@ -24,7 +25,8 @@ class LiveSyncService implements ILiveSyncService {
2425
private $options: IOptions,
2526
private $logger: ILogger,
2627
private $dispatcher: IFutureDispatcher,
27-
private $hooksService: IHooksService) { }
28+
private $hooksService: IHooksService,
29+
private $processService: IProcessService) { }
2830

2931
private ensureAndroidFrameworkVersion(platformData: IPlatformData): IFuture<void> { // TODO: this can be moved inside command or canExecute function
3032
return (() => {
@@ -130,7 +132,7 @@ class LiveSyncService implements ILiveSyncService {
130132
private partialSync(syncWorkingDirectory: string, onChangedActions: ((event: string, filePath: string, dispatcher: IFutureDispatcher) => void )[]): void {
131133
let that = this;
132134

133-
gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
135+
let gazeWatcher = gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
134136
this.on('all', (event: string, filePath: string) => {
135137
fiberBootstrap.run(() => {
136138
that.$dispatcher.dispatch(() => (() => {
@@ -147,6 +149,7 @@ class LiveSyncService implements ILiveSyncService {
147149
});
148150
});
149151

152+
this.$processService.attachToProcessExitSignals(this, () => Future.fromResult(gazeWatcher.close()));
150153
this.$dispatcher.run();
151154
}
152155
}

0 commit comments

Comments
 (0)