From 328d3a4aafc52ff4040b43db7f9e3835843fb98c Mon Sep 17 00:00:00 2001 From: Toma Nikolov Date: Thu, 13 Jul 2017 14:43:07 +0300 Subject: [PATCH] Fix recursive calling of actions. --- lib/definitions/livesync.d.ts | 3 ++- lib/services/livesync/livesync-service.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index 6fa8ae0691..472c76cc50 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -160,9 +160,10 @@ interface ILiveSyncService { * Stops LiveSync operation for specified directory. * @param {string} projectDir The directory for which to stop the operation. * @param {string[]} @optional deviceIdentifiers Device ids for which to stop the application. In case nothing is passed, LiveSync operation will be stopped for all devices. + * @param { shouldAwaitAllActions: boolean } @optional stopOptions Specifies whether we should await all actions. * @returns {Promise} */ - stopLiveSync(projectDir: string, deviceIdentifiers?: string[]): Promise; + stopLiveSync(projectDir: string, deviceIdentifiers?: string[], stopOptions?: { shouldAwaitAllActions: boolean }): Promise; } /** diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index f87aa65301..db10860bee 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -40,7 +40,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { await this.liveSyncOperation(deviceDescriptors, liveSyncData, projectData); } - public async stopLiveSync(projectDir: string, deviceIdentifiers?: string[]): Promise { + public async stopLiveSync(projectDir: string, deviceIdentifiers?: string[], stopOptions?: { shouldAwaitAllActions: boolean }): Promise { const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectDir]; if (liveSyncProcessInfo) { @@ -67,7 +67,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { liveSyncProcessInfo.watcherInfo = null; - if (liveSyncProcessInfo.actionsChain) { + if (liveSyncProcessInfo.actionsChain && (!stopOptions || stopOptions.shouldAwaitAllActions)) { await liveSyncProcessInfo.actionsChain; } @@ -127,7 +127,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { await this.initialSync(projectData, deviceDescriptorsForInitialSync, liveSyncData); - if (!liveSyncData.skipWatcher && deviceDescriptors && deviceDescriptors.length) { + if (!liveSyncData.skipWatcher && this.liveSyncProcessesInfo[projectData.projectDir].deviceDescriptors.length) { // Should be set after prepare this.$injector.resolve("usbLiveSyncService").isInitialized = true; @@ -250,7 +250,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { applicationIdentifier: projectData.projectId }); - await this.stopLiveSync(projectData.projectDir, [device.deviceInfo.identifier]); + await this.stopLiveSync(projectData.projectDir, [device.deviceInfo.identifier], { shouldAwaitAllActions: false }); } }; @@ -360,7 +360,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { applicationIdentifier: projectData.projectId }); - await this.stopLiveSync(projectData.projectDir, [deviceError.deviceIdentifier]); + await this.stopLiveSync(projectData.projectDir, [deviceError.deviceIdentifier], { shouldAwaitAllActions: false }); } } }