Skip to content

Commit

Permalink
Keep a singleton of connectivity monitor in GRPCHost
Browse files Browse the repository at this point in the history
  • Loading branch information
Muxi Yan committed Oct 22, 2016
1 parent 6ac6a52 commit ad93106
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/objective-c/GRPCClient/private/GRPCHost.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,16 @@ - (nullable instancetype)initWithAddress:(NSString *)address {
_address = address;
_secure = YES;
kHostCache[address] = self;

// When there is host in the cache, keep a single monitor to the network
// to
// flush the cache if the connectivity status changed
if (!connectivityMonitor) {
connectivityMonitor =
[GRPCConnectivityMonitor monitorWithHost:hostURL.host];
void (^handler)() = ^{
[GRPCHost flushChannelCache];
};
[connectivityMonitor handleLossWithHandler:handler
wifiStatusChangeHandler:handler];
}
}
// Keep a single monitor to flush the cache if the connectivity status changed
if (!connectivityMonitor) {
connectivityMonitor =
[GRPCConnectivityMonitor monitorWithHost:hostURL.host];
void (^handler)() = ^{
[GRPCHost flushChannelCache];
};
[connectivityMonitor handleLossWithHandler:handler
wifiStatusChangeHandler:handler];
}
}
return self;
Expand All @@ -125,8 +122,6 @@ + (void)flushChannelCache {
BOOL * _Nonnull stop) {
[host disconnect];
}];
[kHostCache removeAllObjects];
connectivityMonitor = nil;
}
}

Expand Down

0 comments on commit ad93106

Please sign in to comment.