@@ -22,6 +22,8 @@ import {getQueryParams} from '../utils/query_params';
22
22
import { ExperimentService } from './experiment_service' ;
23
23
import { io , Socket } from 'socket.io-client' ; // Import Socket.IO client
24
24
25
+ const STREAM_END = '<stream_end>' ;
26
+
25
27
// Pick 500ms as the minimum duration before showing a progress/busy indicator
26
28
// for the channel.
27
29
// See: https://github.com/google/mesop/issues/365
@@ -137,17 +139,14 @@ export class Channel {
137
139
// Looks like Angular has a bug where it's not intercepting EventSource onmessage.
138
140
zone . run ( ( ) => {
139
141
const data = ( e as any ) . data ;
140
- if ( data === '<stream_end>' ) {
142
+ if ( data === STREAM_END ) {
141
143
this . eventSource . close ( ) ;
142
144
this . status = ChannelStatus . CLOSED ;
143
145
clearTimeout ( this . isWaitingTimeout ) ;
144
146
this . isWaiting = false ;
145
147
this . _isHotReloading = false ;
146
148
this . logger . log ( { type : 'StreamEnd' } ) ;
147
- if ( this . queuedEvents . length ) {
148
- const queuedEvent = this . queuedEvents . shift ( ) ! ;
149
- queuedEvent ( ) ;
150
- }
149
+ this . dequeueEvent ( ) ;
151
150
return ;
152
151
}
153
152
@@ -159,9 +158,6 @@ export class Channel {
159
158
} ) ;
160
159
}
161
160
162
- /**
163
- * Initialize WebSocket connection using Socket.IO.
164
- */
165
161
private initWebSocket ( initParams : InitParams , request : UiRequest ) {
166
162
if ( this . socket ) {
167
163
this . status = ChannelStatus . OPEN ;
@@ -194,14 +190,11 @@ export class Channel {
194
190
const prefix = 'data: ' ;
195
191
const payloadData = ( data . data . slice ( prefix . length ) as string ) . trimEnd ( ) ;
196
192
zone . run ( ( ) => {
197
- if ( payloadData === '<stream_end>' ) {
193
+ if ( payloadData === STREAM_END ) {
198
194
this . _isHotReloading = false ;
199
195
this . status = ChannelStatus . CLOSED ;
200
196
this . logger . log ( { type : 'StreamEnd' } ) ;
201
- if ( this . queuedEvents . length ) {
202
- const queuedEvent = this . queuedEvents . shift ( ) ! ;
203
- queuedEvent ( ) ;
204
- }
197
+ this . dequeueEvent ( ) ;
205
198
return ;
206
199
}
207
200
@@ -229,9 +222,6 @@ export class Channel {
229
222
} ) ;
230
223
}
231
224
232
- /**
233
- * Handle UiResponse from the server.
234
- */
235
225
private handleUiResponse (
236
226
request : UiRequest ,
237
227
uiResponse : UiResponse ,
@@ -408,6 +398,13 @@ export class Channel {
408
398
}
409
399
}
410
400
401
+ private dequeueEvent ( ) {
402
+ if ( this . queuedEvents . length ) {
403
+ const queuedEvent = this . queuedEvents . shift ( ) ! ;
404
+ queuedEvent ( ) ;
405
+ }
406
+ }
407
+
411
408
checkForHotReload ( ) {
412
409
const pollHotReloadEndpoint = async ( ) => {
413
410
try {
0 commit comments