Class: SC.RunLoop


Extends SC.Object.

The run loop provides a universal system for coordinating events within your application. The run loop processes timers as well as pending observer notifications within your application.

To use a RunLoop within your application, you should make sure your event handlers always begin and end with SC.RunLoop.begin() and SC.RunLoop.end()

The RunLoop is important because bindings do not fire until the end of your run loop is reached. This improves the performance of your application.

Example:

This is how you could write your mouseup handler in jQuery:

$('#okButton').on('click', function () {
    SC.run(function () {

      // handle click event...

    }); // allows bindings to trigger...
  });

Defined in: run_loop.js

Since:
SproutCore 1.0

Field Summary

Class Methods

Instance Methods

Field Detail

SC.RunLoop.currentRunLoop SC.RunLoop

The current run loop. This is created automatically the first time you call begin().

SC.RunLoop.runLoopClass Class

The default RunLoop class. If you choose to extend the RunLoop, you can set this property to make sure your class is used instead.

Class Method Detail

begin()

Begins a new run loop on the currentRunLoop. If you are already in a runloop, this method has no effect.

Returns:
SC.RunLoop
receiver
end()

Ends the run loop on the currentRunLoop. This will deliver any final pending notifications and schedule any additional necessary cleanup.

Returns:
SC.RunLoop
receiver
isRunLoopInProgress()
Returns YES when a run loop is in progress
Returns:
Boolean
kill()

Call this to kill the current run loop--stopping all propagation of bindings and observers and clearing all timers.

This is useful if you are popping up an error catcher: you need a run loop for the error catcher, but you don't want the app itself to continue running.

wrapFunction(func)

Wraps the passed function in code that ensures a run loop will surround it when run.

Parameters:
func

Instance Method Detail

beginRunLoop()

Call this method whenver you begin executing code.

This is typically invoked automatically for you from event handlers and the timeout handler. If you call setTimeout() or setInterval() yourself, you may need to invoke this yourself.

Returns:
SC.RunLoop
receiver
cancelTimer(timer)

Removes the named timer from the timeout queue. If the timer is not currently scheduled, this method will have no effect.


Defined in: run_loop.js.
Parameters:
timer SC.Timer
the timer to schedule
Returns:
SC.RunLoop
receiver
endRunLoop()

Call this method whenever you are done executing code.

This is typically invoked automatically for you from event handlers and the timeout handler. If you call setTimeout() or setInterval() yourself you may need to invoke this yourself.

Returns:
SC.RunLoop
receiver
fireExpiredTimers()

Invokes any timers that have expired since this method was last called. Usually you will not call this method directly, but it will be invoked automatically at the end of the run loop.


Defined in: run_loop.js.
Returns:
Boolean
YES if timers were fired, NO otherwise
flushAllPending()
Repeatedly flushes all bindings, observers, and other queued functions until all queues are empty.
flushApplicationQueues()

Executes any pending events at the end of the run loop. This method is called automatically at the end of a run loop to flush any pending queue changes.

The default method will invoke any one time methods and then sync any bindings that might have changed. You can override this method in a subclass if you like to handle additional cleanup.

This method must return YES if it found any items pending in its queues to take action on. endRunLoop will invoke this method repeatedly until the method returns NO. This way if any if your final executing code causes additional queues to trigger, then can be flushed again.

Returns:
Boolean
YES if items were found in any queue, NO otherwise
invokeLast(target, method)

Invokes the passed target/method pair at the very end of the run loop, once all other delayed invoke queues have been flushed. Use this to schedule cleanup methods at the end of the run loop once all other work (including rendering) has finished.

If you call this with the same target/method pair multiple times it will only invoke the pair only once at the end of the runloop.

Usually you will not call this method directly but use invokeLast() defined on SC.Object.

Note that in development mode only, the object and method that call this method will be recorded, for help in debugging scheduled code.

Parameters:
target Object
method Function
Returns:
SC.RunLoop
receiver
invokeNext(target, method)

Invokes the passed target/method pair once at the beginning of the next run of the run loop, before any other methods (including events) are processed. Use this to defer painting to make views more responsive.

If you call this with the same target/method pair multiple times it will only invoke the pair only once at the beginning of the next runloop.

Usually you will not call this method directly but use invokeNext() defined on SC.Object.

Parameters:
target Object
method Function
Returns:
SC.RunLoop
receiver
invokeOnce(target, method)

Invokes the passed target/method pair once at the end of the runloop. You can call this method as many times as you like and the method will only be invoked once.

Usually you will not call this method directly but use invokeOnce() defined on SC.Object.

Note that in development mode only, the object and method that call this method will be recorded, for help in debugging scheduled code.

Parameters:
target Object
method Function
Returns:
SC.RunLoop
receiver
isRunLoopInProgress()
YES when a run loop is in progress
scheduleTimer(timer, runTime)

Schedules a timer to execute at the specified runTime. You will not usually call this method directly. Instead you should work with SC.Timer, which will manage both creating the timer and scheduling it.

Calling this method on a timer that is already scheduled will remove it from the existing schedule and reschedule it.


Defined in: run_loop.js.
Parameters:
timer SC.Timer
the timer to schedule
runTime Time
the time offset when you want this to run
Returns:
SC.RunLoop
receiver
startTime()

The time the current run loop began executing.

All timers scheduled during this run loop will begin executing as if they were scheduled at this time.


Defined in: run_loop.js.
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)