RACEmptySignal.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // RACEmptySignal.m
  3. // ReactiveObjC
  4. //
  5. // Created by Justin Spahr-Summers on 2013-10-10.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import "RACEmptySignal.h"
  9. #import "RACScheduler+Private.h"
  10. #import "RACSubscriber.h"
  11. @implementation RACEmptySignal
  12. #pragma mark Properties
  13. // Only allow this signal's name to be customized in DEBUG, since it's
  14. // a singleton in release builds (see +empty).
  15. - (void)setName:(NSString *)name {
  16. #ifdef DEBUG
  17. [super setName:name];
  18. #endif
  19. }
  20. - (NSString *)name {
  21. #ifdef DEBUG
  22. return super.name;
  23. #else
  24. return @"+empty";
  25. #endif
  26. }
  27. #pragma mark Lifecycle
  28. + (RACSignal *)empty {
  29. #ifdef DEBUG
  30. // Create multiple instances of this class in DEBUG so users can set custom
  31. // names on each.
  32. return [[[self alloc] init] setNameWithFormat:@"+empty"];
  33. #else
  34. static id singleton;
  35. static dispatch_once_t pred;
  36. dispatch_once(&pred, ^{
  37. singleton = [[self alloc] init];
  38. });
  39. return singleton;
  40. #endif
  41. }
  42. #pragma mark Subscription
  43. - (RACDisposable *)subscribe:(id<RACSubscriber>)subscriber {
  44. NSCParameterAssert(subscriber != nil);
  45. return [RACScheduler.subscriptionScheduler schedule:^{
  46. [subscriber sendCompleted];
  47. }];
  48. }
  49. @end