Няма описание

FIRInstanceIDCombinedHandler.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRInstanceIDCombinedHandler.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. typedef void (^FIRInstanseIDHandler)(id _Nullable result, NSError *_Nullable error);
  19. @interface FIRInstanceIDCombinedHandler <ResultType>()
  20. @property(atomic, readonly, strong) NSMutableArray<FIRInstanseIDHandler> *handlers;
  21. @end
  22. NS_ASSUME_NONNULL_END
  23. @implementation FIRInstanceIDCombinedHandler
  24. - (instancetype)init {
  25. self = [super init];
  26. if (self) {
  27. _handlers = [NSMutableArray array];
  28. }
  29. return self;
  30. }
  31. - (void)addHandler:(FIRInstanseIDHandler)handler {
  32. if (!handler) {
  33. return;
  34. }
  35. @synchronized(self) {
  36. [self.handlers addObject:handler];
  37. }
  38. }
  39. - (FIRInstanseIDHandler)combinedHandler {
  40. FIRInstanseIDHandler combinedHandler = nil;
  41. @synchronized(self) {
  42. NSArray<FIRInstanseIDHandler> *handlers = [self.handlers copy];
  43. combinedHandler = ^(id result, NSError *error) {
  44. for (FIRInstanseIDHandler handler in handlers) {
  45. handler(result, error);
  46. }
  47. };
  48. }
  49. return combinedHandler;
  50. }
  51. @end