@@ -364,11 +364,9 @@ export class SessionController extends Loggable {
364364 let card = this . hydratedQ . dequeue ( ) ;
365365
366366 // If no hydrated card but source cards available, wait for hydration
367- if ( ! card && this . hasAvailableCards ( ) && ! this . hydration_in_progress ) {
368- this . hydration_in_progress = true ;
369- await this . _fillHydratedQueue ( ) ;
370- this . hydration_in_progress = false ;
371- card = this . hydratedQ . dequeue ( ) ;
367+ if ( ! card && this . hasAvailableCards ( ) ) {
368+ void this . _fillHydratedQueue ( ) ; // Start hydration in background
369+ card = await this . nextHydratedCard ( ) ; // Wait for first available card
372370 }
373371
374372 // Trigger background hydration to maintain cache (async, non-blocking)
@@ -434,6 +432,14 @@ export class SessionController extends Loggable {
434432 return this . reviewQ . length > 0 || this . newQ . length > 0 || this . failedQ . length > 0 ;
435433 }
436434
435+ private async nextHydratedCard ( ) : Promise < HydratedCard | null > {
436+ // Wait for a card to become available in hydratedQ
437+ while ( this . hydratedQ . length === 0 && this . hasAvailableCards ( ) ) {
438+ await new Promise ( ( resolve ) => setTimeout ( resolve , 25 ) ) ; // Short polling interval
439+ }
440+ return this . hydratedQ . dequeue ( ) ;
441+ }
442+
437443 private async _fillHydratedQueue ( ) {
438444 if ( this . hydration_in_progress ) {
439445 return ; // Prevent concurrent hydration
0 commit comments