Inherits from NSObject
Declared in RACScheduler.h

Overview

Schedulers are used to control when and where work is performed. An interface for use by subclasses.

Subclasses should use performAsCurrentScheduler: to do the actual block invocation so that [RACScheduler currentScheduler] behaves as expected.

Note that RACSchedulers are expected to be serial. Subclasses must honor that contract. See RACTargetQueueScheduler for a queue-based scheduler which will enforce the serialization guarantee.

Tasks

Other Methods

Extension Methods

Deprecated Methods

Class Methods

currentScheduler

+ (RACScheduler *)currentScheduler
Discussion

The current scheduler. This will only be valid when used from within a [RACScheduler schedule:] block or when on the main thread.

Declared In

RACScheduler.h

immediateScheduler

+ (RACScheduler *)immediateScheduler
Discussion

A singleton scheduler that immediately executes the blocks it is given.

Note: Unlike most other schedulers, this does not set the current scheduler. There may still be a valid currentScheduler if this is used within a block scheduled on a different scheduler.

Declared In

RACScheduler.h

mainThreadScheduler

+ (RACScheduler *)mainThreadScheduler
Discussion

A singleton scheduler that executes blocks in the main thread.

Declared In

RACScheduler.h

scheduler

+ (RACScheduler *)scheduler
Discussion

Invokes schedulerWithPriority: with RACSchedulerPriorityDefault.

Declared In

RACScheduler.h

schedulerWithPriority:

+ (RACScheduler *)schedulerWithPriority:(RACSchedulerPriority)priority
Discussion

Invokes schedulerWithPriority:name: with a default name.

Declared In

RACScheduler.h

schedulerWithPriority:name:

+ (RACScheduler *)schedulerWithPriority:(RACSchedulerPriority)priority name:(NSString *)name
Discussion

Creates and returns a new background scheduler with the given priority and name. The name is for debug and instrumentation purposes only.

Scheduler creation is cheap. It’s unnecessary to save the result of this method call unless you want to serialize some actions on the same background scheduler.

Declared In

RACScheduler.h

schedulerWithQueue:name:

+ (RACScheduler *)schedulerWithQueue:(dispatch_queue_t)queue name:(NSString *)name

Instance Methods

after:repeatingEvery:withLeeway:schedule:

- (RACDisposable *)after:(NSDate *)date repeatingEvery:(NSTimeInterval)interval withLeeway:(NSTimeInterval)leeway schedule:(void ( ^ ) ( void ))block
Discussion

Reschedule the given block at a particular interval, starting at a specific time, and with a given leeway for deferral.

Note that blocks scheduled for a certain time will not preempt any other scheduled work that is executing at the time.

Regardless of the value of leeway, the given block may not execute exactly at when or exactly on successive intervals, whether due to system load or because another block is currently being run on the scheduler.

It is considered undefined behavior to invoke this method on the immediateScheduler.

date - The earliest time at which block should begin executing. The block may not execute immediately at this time, whether due to system load or another block on the scheduler currently being run. Cannot be nil. interval - The interval at which the block should be rescheduled, starting from date. This will use the system wall clock, to avoid skew when the computer goes to sleep. leeway - A hint to the system indicating the number of seconds that each scheduling can be deferred. Note that this is just a hint, and there may be some additional latency no matter what. block - The block to repeatedly schedule for execution. Cannot be nil.

Returns a disposable which can be used to cancel the automatic scheduling and rescheduling, or nil if cancellation is not supported.

Declared In

RACScheduler.h

after:schedule:

- (RACDisposable *)after:(NSDate *)date schedule:(void ( ^ ) ( void ))block
Discussion

Schedule the given block for execution on the scheduler at or after a specific time.

Note that blocks scheduled for a certain time will not preempt any other scheduled work that is executing at the time.

When invoked on the immediateScheduler, the calling thread will block until the specified time.

date - The earliest time at which block should begin executing. The block may not execute immediately at this time, whether due to system load or another block on the scheduler currently being run. Cannot be nil. block - The block to schedule for execution. Cannot be nil.

Returns a disposable which can be used to cancel the scheduled block before it begins executing, or nil if cancellation is not supported.

Declared In

RACScheduler.h

afterDelay:schedule:

- (RACDisposable *)afterDelay:(NSTimeInterval)delay schedule:(void ( ^ ) ( void ))block
Discussion

Schedule the given block for execution on the scheduler after the delay.

Converts the delay into an NSDate, then invokes after:schedule:.

Declared In

RACScheduler.h

performAsCurrentScheduler:

- (void)performAsCurrentScheduler:(void ( ^ ) ( void ))block
Discussion

Performs the given block with the receiver as the current scheduler for its thread. This should only be called by subclasses to perform their scheduled blocks.

block - The block to execute. Cannot be NULL.

Declared In

RACScheduler+Subclass.h

schedule:

- (RACDisposable *)schedule:(void ( ^ ) ( void ))block
Discussion

Schedule the given block for execution on the scheduler.

Scheduled blocks will be executed in the order in which they were scheduled.

block - The block to schedule for execution. Cannot be nil.

Returns a disposable which can be used to cancel the scheduled block before it begins executing, or nil if cancellation is not supported.

Declared In

RACScheduler.h

scheduleRecursiveBlock:

- (RACDisposable *)scheduleRecursiveBlock:(RACSchedulerRecursiveBlock)recursiveBlock
Discussion

Schedule the given recursive block for execution on the scheduler. The scheduler will automatically flatten any recursive scheduling into iteration instead, so this can be used without issue for blocks that may keep invoking themselves forever.

Scheduled blocks will be executed in the order in which they were scheduled.

recursiveBlock - The block to schedule for execution. When invoked, the recursive block will be passed a void (^)(void) block which will reschedule the recursive block at the end of the receiver’s queue. This passed-in block will automatically skip scheduling if the scheduling of the recursiveBlock was disposed in the meantime.

Returns a disposable which can be used to cancel the scheduled block before it begins executing, or to stop it from rescheduling if it’s already begun execution.

Declared In

RACScheduler.h