packages/bloc_concurrency/README.md
A Dart package that exposes custom event transformers inspired by ember concurrency. Built to work with bloc.
Learn more at bloclibrary.dev!
Our top sponsors are shown below! [Become a Sponsor]
<table style="background-color: white; border: 1px solid black"> <tbody> <tr> <td align="center" style="border: 1px solid black"> <a href="https://shorebird.dev"></a> </td> <td align="center" style="border: 1px solid black"> <a href="https://getstream.io/chat/flutter/tutorial/?utm_source=Github&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=Github_Jan2022_FlutterChat&utm_term=bloc"></a> </td> <td align="center" style="border: 1px solid black"> <a href="https://rettelgame.com/"></a> </td> </tr> </tbody> </table>bloc_concurrency provides an opinionated set of event transformers:
concurrent - process events concurrentlysequential - process events sequentiallydroppable - ignore any events added while an event is processingrestartable - process only the latest event and cancel previous event handlersimport 'package:bloc/bloc.dart';
import 'package:bloc_concurrency/bloc_concurrency.dart';
sealed class CounterEvent {}
final class CounterIncrementPressed extends CounterEvent {}
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncrementPressed>(
(event, emit) async {
await Future.delayed(Duration(seconds: 1));
emit(state + 1);
},
/// Specify a custom event transformer from `package:bloc_concurrency`
/// in this case events will be processed sequentially.
transformer: sequential(),
);
}
}