RACErrorSignal.m 903 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // RACErrorSignal.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 "RACErrorSignal.h"
  9. #import "RACScheduler+Private.h"
  10. #import "RACSubscriber.h"
  11. @interface RACErrorSignal ()
  12. // The error to send upon subscription.
  13. @property (nonatomic, strong, readonly) NSError *error;
  14. @end
  15. @implementation RACErrorSignal
  16. #pragma mark Lifecycle
  17. + (RACSignal *)error:(NSError *)error {
  18. RACErrorSignal *signal = [[self alloc] init];
  19. signal->_error = error;
  20. #ifdef DEBUG
  21. [signal setNameWithFormat:@"+error: %@", error];
  22. #else
  23. signal.name = @"+error:";
  24. #endif
  25. return signal;
  26. }
  27. #pragma mark Subscription
  28. - (RACDisposable *)subscribe:(id<RACSubscriber>)subscriber {
  29. NSCParameterAssert(subscriber != nil);
  30. return [RACScheduler.subscriptionScheduler schedule:^{
  31. [subscriber sendError:self.error];
  32. }];
  33. }
  34. @end