Skip to content

Commit

Permalink
Mark connectivity closures as nullable and check null when invoking them
Browse files Browse the repository at this point in the history
  • Loading branch information
Muxi Yan committed Oct 31, 2016
1 parent aea7d31 commit 411969a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
* Only one handler is active at a time, so if this method is called again before the previous
* handler has been called, it might never be called at all (or yes, if it has already been queued).
*/
- (void)handleLossWithHandler:(void (^)())lossHandler
wifiStatusChangeHandler:(void (^)())wifiStatusChangeHandler;
- (void)handleLossWithHandler:(nullable void (^)())lossHandler
wifiStatusChangeHandler:(nullable void (^)())wifiStatusChangeHandler;
@end
9 changes: 5 additions & 4 deletions src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ + (nullable instancetype)monitorWithHost:(nonnull NSString *)host {
return returnValue;
}

- (void)handleLossWithHandler:(void (^)())lossHandler
wifiStatusChangeHandler:(void (^)())wifiStatusChangeHandler {
- (void)handleLossWithHandler:(nullable void (^)())lossHandler
wifiStatusChangeHandler:(nullable void (^)())wifiStatusChangeHandler {
__weak typeof(self) weakSelf = self;
[self startListeningWithHandler:^(GRPCReachabilityFlags *flags) {
typeof(self) strongSelf = weakSelf;
if (strongSelf) {
if (!flags.reachable) {
if (lossHandler && !flags.reachable) {
lossHandler();
} else if (strongSelf->_previousReachabilityFlags &&
} else if (wifiStatusChangeHandler &&
strongSelf->_previousReachabilityFlags &&
(flags.isWWAN ^
strongSelf->_previousReachabilityFlags.isWWAN)) {
wifiStatusChangeHandler();
Expand Down

0 comments on commit 411969a

Please sign in to comment.