@@ -29,10 +29,12 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
29
29
private $errors : IErrors ,
30
30
private $fs : IFileSystem ,
31
31
private $logger : ILogger ,
32
- private $mobileHelper : Mobile . IMobileHelper ) {
32
+ private $mobileHelper : Mobile . IMobileHelper ,
33
+ private $processService : IProcessService ) {
33
34
this . operationPromises = Object . create ( null ) ;
34
35
this . socketError = null ;
35
36
this . socketConnection = null ;
37
+ this . $processService . attachToProcessExitSignals ( this , this . dispose ) ;
36
38
}
37
39
38
40
public async connect ( configuration : IAndroidLivesyncToolConfiguration ) : Promise < void > {
@@ -135,21 +137,22 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
135
137
headerBuffer . writeUInt8 ( doRefreshCode , offset ) ;
136
138
const hash = crypto . createHash ( "md5" ) . update ( headerBuffer ) . digest ( ) ;
137
139
138
- this . operationPromises [ id ] = {
139
- resolve,
140
- reject,
141
- socketId
142
- } ;
143
-
144
140
this . socketConnection . write ( headerBuffer ) ;
145
141
this . socketConnection . write ( hash ) ;
146
142
147
143
timeout = timeout || SYNC_OPERATION_TIMEOUT ;
148
- setTimeout ( ( ) => {
144
+ const timeoutId = setTimeout ( ( ) => {
149
145
if ( this . isOperationInProgress ( id ) ) {
150
146
this . handleSocketError ( socketId , "Sync operation is taking too long" ) ;
151
147
}
152
148
} , timeout ) ;
149
+
150
+ this . operationPromises [ id ] = {
151
+ resolve,
152
+ reject,
153
+ socketId,
154
+ timeoutId
155
+ } ;
153
156
} ) ;
154
157
155
158
return operationPromise ;
@@ -216,7 +219,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
216
219
} else {
217
220
const error = this . checkConnectionStatus ( ) ;
218
221
//TODO Destroy method added in node 8.0.0.
219
- //when we depricate node 6.x uncoment the line belolw
222
+ //when we deprecate node 6.x uncomment the line below
220
223
//fileStream.destroy(error);
221
224
reject ( error ) ;
222
225
}
@@ -348,6 +351,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
348
351
const promiseHandler = this . operationPromises [ operationId ] ;
349
352
350
353
if ( promiseHandler ) {
354
+ clearTimeout ( promiseHandler . timeoutId ) ;
351
355
promiseHandler . resolve ( { operationId, didRefresh} ) ;
352
356
delete this . operationPromises [ operationId ] ;
353
357
}
@@ -370,6 +374,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
370
374
. forEach ( operationId => {
371
375
const operationPromise = this . operationPromises [ operationId ] ;
372
376
if ( operationPromise . socketId === socketId ) {
377
+ clearTimeout ( operationPromise . timeoutId ) ;
373
378
operationPromise . reject ( error ) ;
374
379
delete this . operationPromises [ operationId ] ;
375
380
}
@@ -403,5 +408,15 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
403
408
404
409
return this . $mobileHelper . buildDevicePath ( relativeFilePath ) ;
405
410
}
411
+
412
+ private dispose ( ) : void {
413
+ this . end ( ) ;
414
+
415
+ _ . keys ( this . operationPromises )
416
+ . forEach ( operationId => {
417
+ const operationPromise = this . operationPromises [ operationId ] ;
418
+ clearTimeout ( operationPromise . timeoutId ) ;
419
+ } ) ;
420
+ }
406
421
}
407
422
$injector . register ( "androidLivesyncTool" , AndroidLivesyncTool ) ;
0 commit comments