//
//  YSRACImmediateScheduler.m
//  ReactiveObjC
//
//  Created by Josh Abernathy on 11/30/12.
//  Copyright (c) 2012 GitHub, Inc. All rights reserved.
//

#import "YSRACImmediateScheduler.h"
#import "YSRACScheduler+Private.h"

@implementation YSRACImmediateScheduler

#pragma mark Lifecycle

- (instancetype)init {
	return [super initWithName:@"org.reactivecocoa.ReactiveObjC.YSRACScheduler.immediateScheduler"];
}

#pragma mark YSRACScheduler

- (YSRACDisposable *)schedule:(void (^)(void))block {
	NSCParameterAssert(block != NULL);

	block();
	return nil;
}

- (YSRACDisposable *)after:(NSDate *)date schedule:(void (^)(void))block {
	NSCParameterAssert(date != nil);
	NSCParameterAssert(block != NULL);

	[NSThread sleepUntilDate:date];
	block();

	return nil;
}

- (YSRACDisposable *)after:(NSDate *)date repeatingEvery:(NSTimeInterval)interval withLeeway:(NSTimeInterval)leeway schedule:(void (^)(void))block {
	NSCAssert(NO, @"+[YSRACScheduler immediateScheduler] does not support %@.", NSStringFromSelector(_cmd));
	return nil;
}

- (YSRACDisposable *)scheduleRecursiveBlock:(YSRACSchedulerRecursiveBlock)recursiveBlock {
	for (__block NSUInteger remaining = 1; remaining > 0; remaining--) {
		recursiveBlock(^{
			remaining++;
		});
	}

	return nil;
}

@end
