Skip to content

Commit 3f16962

Browse files
Merge pull request #1981 from NativeScript/KristinaKoeva/ProcessEventHandlers
Use the new processService for destroying the live sync socket
2 parents 6cd8e96 + b416a89 commit 3f16962

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-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, 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

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class LiveSyncService implements ILiveSyncService {
2424
private $options: IOptions,
2525
private $logger: ILogger,
2626
private $dispatcher: IFutureDispatcher,
27-
private $hooksService: IHooksService) { }
27+
private $hooksService: IHooksService,
28+
private $processService: IProcessService) { }
2829

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

133-
gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
134+
let gazeWatcher = gaze("**/*", { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
134135
this.on('all', (event: string, filePath: string) => {
135136
fiberBootstrap.run(() => {
136137
that.$dispatcher.dispatch(() => (() => {
@@ -147,6 +148,7 @@ class LiveSyncService implements ILiveSyncService {
147148
});
148149
});
149150

151+
this.$processService.attachToProcessExitSignals(this, gazeWatcher.close);
150152
this.$dispatcher.run();
151153
}
152154
}

0 commit comments

Comments
 (0)