@@ -36,18 +36,28 @@ interface IPendingQueueItem extends IQueueItem {
3636function wrapPromise < TR = any , TW = any > (
3737 process : ( cb : C . ICallbackA < TR , TW > ) => void ,
3838 callback ?: C . ICallbackA < TR , TW > ,
39- ) : Promise < any > | void {
39+ ) : Promise < any > | undefined {
4040
4141 if ( callback ) {
4242
4343 process ( callback ) ;
44+ return undefined ;
4445 }
4546 else {
4647
4748 return new Promise (
48- ( resolve , reject ) => process (
49- ( e : any , r ?: any ) => e ? reject ( e ) : resolve ( r )
50- )
49+ ( resolve , reject ) => {
50+ process (
51+ ( e : any , r ?: any ) => {
52+ if ( e ) {
53+ reject ( e ) ;
54+ }
55+ else {
56+ resolve ( r ) ;
57+ }
58+ }
59+ ) ;
60+ }
5161 ) ;
5262 }
5363}
@@ -68,15 +78,15 @@ export class ProtocolClient
6878
6979 private _sendingQueue : IQueueItem [ ] = [ ] ;
7080
71- private _decoder : C . IDecoder ;
81+ private readonly _decoder : C . IDecoder ;
7282
73- private _encoder : C . IEncoder ;
83+ private readonly _encoder : C . IEncoder ;
7484
7585 private _ready : boolean = false ;
7686
77- private _subscribeMode : boolean ;
87+ private readonly _subscribeMode : boolean ;
7888
79- private _pipelineMode : boolean ;
89+ private readonly _pipelineMode : boolean ;
8090
8191 public readonly host : string ;
8292
@@ -112,7 +122,7 @@ export class ProtocolClient
112122
113123 this . _decoder . on ( 'data' , ( type , data ) : void => {
114124
115- const it = this . _executingQueue . shift ( ) as IQueueItem ;
125+ const it = this . _executingQueue . shift ( ) ! ;
116126
117127 switch ( type ) {
118128 case C . EDataType . FAILURE :
@@ -201,7 +211,7 @@ export class ProtocolClient
201211
202212 this . _decoder . on ( 'data' , ( type , data ) : void => {
203213
204- const cb = this . _executingQueue . shift ( ) as IQueueItem ;
214+ const cb = this . _executingQueue . shift ( ) ! ;
205215
206216 switch ( type ) {
207217 case C . EDataType . FAILURE :
@@ -269,15 +279,25 @@ export class ProtocolClient
269279
270280 this . _pendingQueue = [ ] ;
271281
272- for ( let x of queue ) {
282+ for ( const x of queue ) {
273283
274284 if ( this . _socket . writable ) {
275285
276286 this . _sendingQueue . push ( x ) ;
277287
278288 this . _socket . write (
279289 x . data ,
280- ( e ) => e ? callback ( e ) : this . _executingQueue . push ( this . _sendingQueue . shift ( ) as any )
290+ ( e ) => {
291+
292+ if ( e ) {
293+
294+ callback ( e ) ;
295+ }
296+ else {
297+
298+ this . _executingQueue . push ( this . _sendingQueue . shift ( ) as any ) ;
299+ }
300+ }
281301 ) ;
282302 }
283303 }
@@ -310,7 +330,7 @@ export class ProtocolClient
310330
311331 this . _status = C . EClientStatus . CONNECTING ;
312332
313- // @ts -ignore
333+ // @ts -expect-error
314334 this . _socket . __uuid = ++ this . _uuidCounter ;
315335
316336 this . _timeoutLocked = false ;
@@ -325,7 +345,7 @@ export class ProtocolClient
325345
326346 this . _socket . on ( 'connect' , ( ) => {
327347
328- // @ts -ignore
348+ // @ts -expect-error
329349 if ( this . _socket . __uuid !== this . _uuidCounter ) {
330350
331351 return ;
@@ -357,7 +377,7 @@ export class ProtocolClient
357377 } )
358378 . on ( 'error' , ( e : any ) => {
359379
360- // @ts -ignore
380+ // @ts -expect-error
361381 if ( this . _socket . __uuid !== this . _uuidCounter ) {
362382
363383 return ;
@@ -367,7 +387,7 @@ export class ProtocolClient
367387 } )
368388 . on ( 'close' , ( ) => {
369389
370- // @ts -ignore
390+ // @ts -expect-error
371391 if ( this . _socket . __uuid !== this . _uuidCounter ) {
372392
373393 return ;
@@ -380,7 +400,7 @@ export class ProtocolClient
380400 return ;
381401 }
382402
383- for ( let x of this . _sendingQueue ) {
403+ for ( const x of this . _sendingQueue ) {
384404
385405 try {
386406
@@ -392,7 +412,7 @@ export class ProtocolClient
392412 }
393413 }
394414
395- for ( let x of this . _executingQueue ) {
415+ for ( const x of this . _executingQueue ) {
396416
397417 try {
398418
@@ -522,7 +542,7 @@ export class ProtocolClient
522542 ! this . _socket ?. writable
523543 ) {
524544
525- this . _pendingQueue . push ( { data, callback, count : 1 , result : [ ] } ) ;
545+ this . _pendingQueue . push ( { data, callback, count : 1 , result : [ ] } ) ;
526546 }
527547 else {
528548
@@ -562,7 +582,7 @@ export class ProtocolClient
562582 ! this . _socket ?. writable
563583 ) {
564584
565- this . _pendingQueue . push ( { data, callback, count : cmds . length , result : [ ] } ) ;
585+ this . _pendingQueue . push ( { data, callback, count : cmds . length , result : [ ] } ) ;
566586 }
567587 else {
568588
0 commit comments