Bloc: [Feature Request] Support Synchronous Blocs

Created on 7 Oct 2020  路  6Comments  路  Source: felangel/bloc

Is your feature request related to a problem? Please describe.
I have a bloc that I use to manage other blocs and can benefit from a more synchronous design because I find myself waiting for events to be added to a second bloc before continuing
Describe the solution you'd like
Synchronous Blocs

Describe alternatives you've considered
I recently ran across SynchronousStreamController and figured that if blocs extend streams and behave like StreamControllers, then it would make sense that a synchronous bloc can provide the same benefits to async blocs as sync stream controllers to do async stream controllers.

question

Most helpful comment

Synchronous means one after another, so how would that speed up your event dispatching? What you're looking for is probably parallel dispatching of events. To achieve that in your managing bloc you can override how events are being handled.

@override
  Stream<Transition<MyEvent, MyState>> transformEvents(
      Stream<MyEvent> events, transitionFn) {
    return events.flatMap(transitionFn);
  }

As a side note, I personally don't like the whole concept of having a managing bloc.

Thanks for this. I think the issue was knowing when an event was completed processing from start to finish. For me, if that required 2 blocs, I want the resulting state from the final bloc to be considered the end of the action and I can safely continue. I needed something to await. I ended up removing the dependency on the "managing bloc" and doing it directly

All 6 comments

If you're waiting for new events from a bloc before "continuing", why not use BlocListener to listen to new states?

Synchronous means one after another, so how would that speed up your event dispatching? What you're looking for is probably parallel dispatching of events. To achieve that in your managing bloc you can override how events are being handled.

@override
  Stream<Transition<MyEvent, MyState>> transformEvents(
      Stream<MyEvent> events, transitionFn) {
    return events.flatMap(transitionFn);
  }

As a side note, I personally don't like the whole concept of having a managing bloc.

Synchronous means one after another, so how would that speed up your event dispatching? What you're looking for is probably parallel dispatching of events. To achieve that in your managing bloc you can override how events are being handled.

@override
  Stream<Transition<MyEvent, MyState>> transformEvents(
      Stream<MyEvent> events, transitionFn) {
    return events.flatMap(transitionFn);
  }

As a side note, I personally don't like the whole concept of having a managing bloc.

Thanks for this. I think the issue was knowing when an event was completed processing from start to finish. For me, if that required 2 blocs, I want the resulting state from the final bloc to be considered the end of the action and I can safely continue. I needed something to await. I ended up removing the dependency on the "managing bloc" and doing it directly

@ThinkDigitalSoftware was your issue resolved or do you still feel this issue should remain open?

I didn't really have an issue, just thought someone more experienced than I am might find it useful

Sounds good! Closing for now then if there is no additional work needed 馃憤

Was this page helpful?
0 / 5 - 0 ratings