call method
Implementation
@override
Stream<TState> call(
Context<TState> context,
Event event,
NextMiddleware<TState> next,
) async* {
if (event is MultiEvent<TState>) {
if (event.mode == MultiEventMode.queue) {
for (var child in event.events) {
await for (final state in next(context, child)) {
yield state;
}
}
} else {
final mergeController = StreamController<TState>();
var registeredEvents = event.events.length;
event.events.map(
(x) => next(context, x).listen((state) {
mergeController.add(state);
}, onError: (error, stackTrace) {
throw error;
}, onDone: () {
registeredEvents--;
if (registeredEvents == 0) {
mergeController.close();
}
}),
);
await for (final state in mergeController.stream) {
yield state;
}
}
} else {
await for (final state in next(context, event)) {
yield state;
}
}
}