Skip to content

fix(offline_first): await closable streams #552#565

Merged
tshedor merged 1 commit intomainfrom
fix-repository-reset-subscription-close
Jun 23, 2025
Merged

fix(offline_first): await closable streams #552#565
tshedor merged 1 commit intomainfrom
fix-repository-reset-subscription-close

Conversation

@tshedor
Copy link
Collaborator

@tshedor tshedor commented Mar 14, 2025

Ref #555 and #552

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Great news! Jit hasn't found any security issues in your PR. Good Job! 🏆

@tshedor tshedor changed the title fix(offline_first): await closable strings #552 fix(offline_first): await closable streams #552 Mar 14, 2025
@tshedor tshedor mentioned this pull request Mar 14, 2025
@TillJohanndeiter
Copy link

To get rid of my problem i had to do the same with the real time stream controllers

In OfflineFirstWithSupabaseRepository i changed:

final controller = StreamController<List<TModel>>(
      onCancel: () async {
        await channel.unsubscribe();

        final controller =
            supabaseRealtimeSubscriptions[TModel]?[eventType]?[query];
        // https://github.com/GetDutchie/brick/issues/552

        if (controller != null) {
          if (!controller.isClosed &&
              controller.hasListener &&
              !controller.isPaused) {
            await controller.close();
          } else {
            unawaited(controller.close());
          }
        }

After this i had to change the reset method to get rid of concurrency

@override
 Future<void> reset() async {
   await super.reset();

   // Collect controllers to avoid concurrent modification
   final controllers = <StreamController>[];
   for (final subscription in supabaseRealtimeSubscriptions.values) {
     for (final eventType in subscription.values) {
       controllers.addAll(eventType.values);
     }
   }

   for (final controller in controllers) {
     await controller.close();
   }

   supabaseRealtimeSubscriptions.clear();
 }

@tshedor tshedor merged commit 0a149ee into main Jun 23, 2025
6 checks passed
@tshedor tshedor deleted the fix-repository-reset-subscription-close branch June 23, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments