Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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();
 }

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.

3 participants