@@ -81,7 +81,10 @@ export class BoardDiscovery
8181 stop ( ) : Promise < void > {
8282 this . logger . info ( '>>> Stopping boards watcher...' ) ;
8383 return new Promise < void > ( ( resolve , reject ) => {
84- const timeout = this . timeout ( BoardDiscovery . StopWatchTimeout , reject ) ;
84+ const timeout = this . createTimeout (
85+ BoardDiscovery . StopWatchTimeout ,
86+ reject
87+ ) ;
8588 const toDispose = new DisposableCollection ( ) ;
8689 toDispose . pushAll ( [
8790 timeout ,
@@ -107,7 +110,7 @@ export class BoardDiscovery
107110 } ) ;
108111 }
109112
110- private timeout (
113+ private createTimeout (
111114 after : number ,
112115 onTimeout : ( error : Error ) => void
113116 ) : Disposable {
@@ -118,37 +121,22 @@ export class BoardDiscovery
118121 return Disposable . create ( ( ) => clearTimeout ( timer ) ) ;
119122 }
120123
121- private async write (
124+ private async requestStartWatch (
122125 req : BoardListWatchRequest ,
123126 duplex : Duplex
124127 ) : Promise < void > {
125128 return new Promise < void > ( ( resolve , reject ) => {
126- this . logger . info ( `>>> Writing ${ this . toJson ( req ) } to the stream...` ) ;
127129 if (
128130 ! duplex . write ( req , ( err : Error | undefined ) => {
129131 if ( err ) {
130- this . logger . error (
131- `<<< Error ocurred while writing to the stream.` ,
132- err
133- ) ;
134132 reject ( err ) ;
135133 return ;
136134 }
137135 } )
138136 ) {
139- duplex . once ( 'drain' , ( ) => {
140- this . logger . info (
141- `<<< Board list watch request has been successfully written to the stream after the handling backpressure.`
142- ) ;
143- resolve ( ) ;
144- } ) ;
137+ duplex . once ( 'drain' , resolve ) ;
145138 } else {
146- process . nextTick ( ( ) => {
147- this . logger . info (
148- `<<< Board list watch request has been successfully written to the stream.`
149- ) ;
150- resolve ( ) ;
151- } ) ;
139+ process . nextTick ( resolve ) ;
152140 }
153141 } ) ;
154142 }
@@ -302,7 +290,7 @@ export class BoardDiscovery
302290 this . notificationService . notifyAttachedBoardsDidChange ( event ) ;
303291 }
304292 } ) ;
305- await this . write (
293+ await this . requestStartWatch (
306294 new BoardListWatchRequest ( ) . setInstance ( instance ) ,
307295 wrapper . stream
308296 ) ;
0 commit comments