Skip to content

Commit

Permalink
#174 - Fixed Strem has been listened to error
Browse files Browse the repository at this point in the history
  • Loading branch information
Clon1998 committed Jun 3, 2023
1 parent 8714666 commit de546ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/data/data_source/json_rpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:mobileraker/data/dto/jrpc/rpc_response.dart';
import 'package:mobileraker/data/model/hive/machine.dart';
import 'package:mobileraker/logger.dart';
import 'package:mobileraker/util/misc.dart';
import 'package:rxdart/rxdart.dart';
import 'package:web_socket_channel/io.dart';

enum ClientState { disconnected, connecting, connected, error }
Expand Down Expand Up @@ -114,8 +115,8 @@ class JsonRpcClient {

StreamSubscription? _channelSub;

final StreamController<ClientState> _stateStream = StreamController()
..add(ClientState.disconnected);
final BehaviorSubject<ClientState> _stateStream =
BehaviorSubject.seeded(ClientState.disconnected);

Stream<ClientState> get stateStream => _stateStream.stream;

Expand Down
17 changes: 8 additions & 9 deletions lib/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ void setupLogger() {
Logger.level = Level.info;
memoryOutput = MemoryOutput(bufferSize: 200, secondOutput: ConsoleOutput());
logger = Logger(
printer: PrettyPrinter(methodCount: 0, noBoxingByDefault: true, colors: !Platform.isIOS),
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 200,
noBoxingByDefault: true,
colors: !Platform.isIOS),
output: memoryOutput,
filter: ProductionFilter(),
);
Expand All @@ -26,19 +30,15 @@ class RiverPodLogger extends ProviderObserver {
@override
void providerDidFail(ProviderBase provider, Object error,
StackTrace stackTrace, ProviderContainer container) {
logger.e(
'${provider.name ?? provider.runtimeType}#${identityHashCode(provider)} failed with',
error,
stackTrace);
logger.e(' ${provider.toIdentityString()} failed with', error, stackTrace);
}

@override
void didDisposeProvider(ProviderBase provider, ProviderContainer container) {
if (['toolheadInfoProvider'].contains(provider.name)) return;

var familiy = provider.from?.toString() ?? '';
logger.wtf(
'RiverPod::DISPOSED:${provider.name ?? provider.runtimeType}#${identityHashCode(provider)} $familiy');
logger.wtf('RiverPod::DISPOSED: ${provider.toIdentityString()} $familiy');
//
// if (provider.name == 'klipperServiceProvider') {
// logger.wtf('RiverPod::klipperServiceProvider: ${container}');
Expand All @@ -48,9 +48,8 @@ class RiverPodLogger extends ProviderObserver {
@override
void didAddProvider(
ProviderBase provider, Object? value, ProviderContainer container) {
var familiy = provider.from?.toString() ?? '';
logger.wtf(
'RiverPod::CREATED-> ${provider.name ?? provider.runtimeType}#${identityHashCode(provider)} $familiy WITH PARENT? ${container.depth}');
'RiverPod::CREATED-> ${provider.toIdentityString()} WITH PARENT? ${container.depth}');
}

@override
Expand Down
17 changes: 17 additions & 0 deletions lib/util/extensions/provider_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';

extension Precision on ProviderBase {
String toIdentityString() {
var leading = '';
if (from != null) {
leading = '($argument)';
}

var trailing = '';
if (name != null) {
trailing = '$name:';
}

return '$trailing$runtimeType#${identityHashCode(this)}$leading';
}
}

0 comments on commit de546ea

Please sign in to comment.