Update global interceptor comment and raise exception

pull/19322/head
Muxi Yan 6 years ago
parent 5b329fd1aa
commit e5de1e5e25
  1. 11
      src/objective-c/GRPCClient/GRPCCall+Interceptor.h
  2. 10
      src/objective-c/GRPCClient/GRPCCall+Interceptor.m

@ -24,8 +24,15 @@
@interface GRPCCall2 (Interceptor)
+ (void)registerGlobalInterceptor:(id<GRPCInterceptorFactory>)interceptorFactory;
/**
* Register a global interceptor's factory in the current process. Only one interceptor can be
* registered in a process. If another one attempts to be registered, an exception will be raised.
*/
+ (void)registerGlobalInterceptor:(nonnull id<GRPCInterceptorFactory>)interceptorFactory;
+ (id<GRPCInterceptorFactory>)globalInterceptorFactory;
/**
* Get the global interceptor's factory.
*/
+ (nullable id<GRPCInterceptorFactory>)globalInterceptorFactory;
@end

@ -26,18 +26,16 @@ static dispatch_once_t onceToken;
@implementation GRPCCall2 (Interceptor)
+ (void)registerGlobalInterceptor:(id<GRPCInterceptorFactory>)interceptorFactory {
if (interceptorFactory == nil) {
return;
}
dispatch_once(&onceToken, ^{
globalInterceptorLock = [[NSLock alloc] init];
});
[globalInterceptorLock lock];
NSAssert(globalInterceptorFactory == nil,
@"Global interceptor is already registered. Only one global interceptor can be "
@"registered in a process");
if (globalInterceptorFactory != nil) {
NSLog(
@"Global interceptor is already registered. Only one global interceptor can be registered "
@"in a process");
[globalInterceptorLock unlock];
[NSException raise:NSInternalInconsistencyException format:@"Global interceptor is already registered. Only one global interceptor can be registered in a process."];
return;
}

Loading…
Cancel
Save