@@ -243,13 +243,49 @@ class SessionService {
243243 *
244244 * @returns {Promise.<Topic[]> }
245245 */
246- async getTopicsWithSessions ( ) {
246+ async getTopicsWithSessions ( resolveCachedDatasets = false ) {
247247 if ( this . realtimeSessionConfig . disable ) {
248248 return Promise . resolve ( [ ] ) ;
249249 }
250+ let datasets = [ ] ;
251+ // Need to wait for MIOs to load for the cached datasets to return.
252+ const cachedDatasets = new Promise ( ( resolve ) => {
253+ // Check once a second
254+ const pollInterval = 1000 ;
255+ let currentLength = 0 ;
256+ let maxIterations = 15 ;
257+ let currentIteration = 0 ;
258+ const checkDatasets = ( ) => {
259+ const result = Object . values ( this . getDatasets ( ) ) ;
260+ if ( result . length > 0 ) {
261+ // Success - we have data
262+ if ( currentLength != 0 ) {
263+ if ( result . length == currentLength ) {
264+ resolve ( result ) ;
265+ }
266+ } else {
267+ currentLength = result . length ;
268+ setTimeout ( checkDatasets , pollInterval ) ;
250269
251- const datasets = Object . values ( this . getDatasets ( ) ) ;
252- const validUrls = datasets . map ( dataset => dataset . options . sessionLADUrl ) . filter ( url => url ) ;
270+ }
271+
272+ } else {
273+ // Check if we've hit our 15 seconds give up interval
274+ if ( currentIteration > maxIterations ) {
275+ resolve ( [ ] ) ;
276+ }
277+ currentIteration ++ ;
278+ setTimeout ( checkDatasets , pollInterval ) ;
279+ }
280+ } ;
281+ checkDatasets ( ) ; // Start polling
282+ } ) ;
283+ if ( resolveCachedDatasets ) {
284+ datasets = await cachedDatasets ;
285+ } else {
286+ datasets = Object . values ( this . getDatasets ( ) ) ;
287+ }
288+ const validUrls = datasets . map ( datasets => datasets . options . sessionLADUrl ) . filter ( url => url ) ;
253289 const sessionLADUrls = validUrls . reduce ( ( uniqueUrls , url ) => {
254290 return uniqueUrls . includes ( url ) ? uniqueUrls : [ ...uniqueUrls , url ] ;
255291 } , [ ] ) ;
0 commit comments