Skip to content

Use the new processService for destroying the live sync socket #1981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions lib/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Mobile.IiOSDevice>(_device);
}

Expand Down Expand Up @@ -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}.`);
Expand Down Expand Up @@ -184,21 +185,6 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
}).future<void>()();
}

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();
Expand Down
6 changes: 4 additions & 2 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> { // TODO: this can be moved inside command or canExecute function
return (() => {
Expand Down Expand Up @@ -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(() => (() => {
Expand All @@ -147,6 +148,7 @@ class LiveSyncService implements ILiveSyncService {
});
});

this.$processService.attachToProcessExitSignals(this, gazeWatcher.close);
this.$dispatcher.run();
}
}
Expand Down