FEventRaiser.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2017 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 "FEventRaiser.h"
  17. #import "FDataEvent.h"
  18. #import "FTypedefs.h"
  19. #import "FUtilities.h"
  20. #import "FTupleUserCallback.h"
  21. #import "FRepo.h"
  22. #import "FRepoManager.h"
  23. @interface FEventRaiser ()
  24. @property (nonatomic, strong) dispatch_queue_t queue;
  25. @end
  26. /**
  27. * This class exists for symmetry with other clients, but since events are async, we don't need to do the complicated
  28. * stuff the JS client does to preserve event order.
  29. */
  30. @implementation FEventRaiser
  31. - (id)init {
  32. [NSException raise:NSInternalInconsistencyException format:@"Can't use default constructor"];
  33. return nil;
  34. }
  35. - (id)initWithQueue:(dispatch_queue_t)queue {
  36. self = [super init];
  37. if (self != nil) {
  38. self->_queue = queue;
  39. }
  40. return self;
  41. }
  42. - (void) raiseEvents:(NSArray *)eventDataList {
  43. for (id<FEvent> event in eventDataList) {
  44. [event fireEventOnQueue:self.queue];
  45. }
  46. }
  47. - (void) raiseCallback:(fbt_void_void)callback {
  48. dispatch_async(self.queue, callback);
  49. }
  50. - (void) raiseCallbacks:(NSArray *)callbackList {
  51. for (fbt_void_void callback in callbackList) {
  52. dispatch_async(self.queue, callback);
  53. }
  54. }
  55. + (void) raiseCallbacks:(NSArray *)callbackList queue:(dispatch_queue_t)queue {
  56. for (fbt_void_void callback in callbackList) {
  57. dispatch_async(queue, callback);
  58. }
  59. }
  60. @end