FEventRaiser.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "FirebaseDatabase/Sources/Core/View/FEventRaiser.h"
  17. #import "FirebaseDatabase/Sources/Core/FRepo.h"
  18. #import "FirebaseDatabase/Sources/Core/FRepoManager.h"
  19. #import "FirebaseDatabase/Sources/Core/View/FDataEvent.h"
  20. #import "FirebaseDatabase/Sources/Utilities/FTypedefs.h"
  21. #import "FirebaseDatabase/Sources/Utilities/FUtilities.h"
  22. #import "FirebaseDatabase/Sources/Utilities/Tuples/FTupleUserCallback.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
  28. * async, we don't need to do the complicated stuff the JS client does to
  29. * preserve event order.
  30. */
  31. @implementation FEventRaiser
  32. - (id)init {
  33. [NSException raise:NSInternalInconsistencyException
  34. format:@"Can't use default constructor"];
  35. return nil;
  36. }
  37. - (id)initWithQueue:(dispatch_queue_t)queue {
  38. self = [super init];
  39. if (self != nil) {
  40. self->_queue = queue;
  41. }
  42. return self;
  43. }
  44. - (void)raiseEvents:(NSArray *)eventDataList {
  45. for (id<FEvent> event in eventDataList) {
  46. [event fireEventOnQueue:self.queue];
  47. }
  48. }
  49. - (void)raiseCallback:(fbt_void_void)callback {
  50. dispatch_async(self.queue, callback);
  51. }
  52. - (void)raiseCallbacks:(NSArray *)callbackList {
  53. for (fbt_void_void callback in callbackList) {
  54. dispatch_async(self.queue, callback);
  55. }
  56. }
  57. + (void)raiseCallbacks:(NSArray *)callbackList queue:(dispatch_queue_t)queue {
  58. for (fbt_void_void callback in callbackList) {
  59. dispatch_async(queue, callback);
  60. }
  61. }
  62. @end