mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-11 23:50:19 -04:00
checkpoint
This commit is contained in:
parent
c516323e7d
commit
31f562119a
70 changed files with 1174 additions and 817 deletions
25
lib/tools/stream_wrapper_cubit.dart
Normal file
25
lib/tools/stream_wrapper_cubit.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
abstract class StreamWrapperCubit<State> extends Cubit<AsyncValue<State>> {
|
||||
StreamWrapperCubit(Stream<State> stream, {State? defaultState})
|
||||
: super(defaultState != null
|
||||
? AsyncValue.data(defaultState)
|
||||
: const AsyncValue.loading()) {
|
||||
_subscription = stream.listen((event) => emit(AsyncValue.data(event)),
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
onError: (Object error, StackTrace stackTrace) {
|
||||
emit(AsyncValue.error(error, stackTrace));
|
||||
});
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _subscription.cancel();
|
||||
await super.close();
|
||||
}
|
||||
}
|
||||
|
||||
late final StreamSubscription<State> _subscription;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue