immich/mobile/lib/domain/utils/event_stream.dart
Adam Gastineau e7aace436d
chore(mobile): Apply stricter linting rules for correctness (#30372)
* chore(mobile): Apply stricter linting rules for correctness

* Added discarded_futures rule
2026-07-30 19:39:24 +00:00

38 lines
860 B
Dart

import 'dart:async';
class Event {
const Event();
}
class EventStream {
EventStream._();
static final EventStream shared = EventStream._();
final StreamController<Event> _controller = StreamController<Event>.broadcast();
void emit(Event event) {
_controller.add(event);
}
Stream<T> where<T extends Event>() {
if (T == Event) {
return _controller.stream as Stream<T>;
}
return _controller.stream.where((event) => event is T).cast<T>();
}
StreamSubscription<T> listen<T extends Event>(
void Function(T event)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return where<T>().listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
}
/// Closes the stream controller
Future<void> dispose() {
return _controller.close();
}
}