//
//  YSRACErrorSignal.m
//  ReactiveObjC
//
//  Created by Justin Spahr-Summers on 2013-10-10.
//  Copyright (c) 2013 GitHub, Inc. All rights reserved.
//

#import "YSRACErrorSignal.h"
#import "YSRACScheduler+Private.h"
#import "YSRACSubscriber.h"

@interface YSRACErrorSignal ()

// The error to send upon subscription.
@property (nonatomic, strong, readonly) NSError *error;

@end

@implementation YSRACErrorSignal

#pragma mark Lifecycle

+ (YSRACSignal *)error:(NSError *)error {
	YSRACErrorSignal *signal = [[self alloc] init];
	signal->_error = error;

#ifdef DEBUG
	[signal setNameWithFormat:@"+error: %@", error];
#else
	signal.name = @"+error:";
#endif

	return signal;
}

#pragma mark Subscription

- (YSRACDisposable *)subscribe:(id<YSRACSubscriber>)subscriber {
	NSCParameterAssert(subscriber != nil);

	return [YSRACScheduler.subscriptionScheduler schedule:^{
		[subscriber sendError:self.error];
	}];
}

@end
