Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run something at the end of the current runloop?

Tags:

ember.js

I want to defer an operation until all bindings have flushed and the current runloop has finished. How do I do that?

like image 660
Jo Liss Avatar asked Jan 14 '13 20:01

Jo Liss


People also ask

What is run loop mode?

A run loop is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none. Run loop management is not entirely automatic.

How do you stop RunLoop?

Run the runloop in the default mode. The run loop can be stopped by calling Stop().

What is run loop in iOS?

Overview. A RunLoop object processes input for sources, such as mouse and keyboard events from the window system and Port objects. A RunLoop object also processes Timer events. Your application neither creates nor explicitly manages RunLoop objects.

What is Uikit RunLoop?

Role of a run loop On iOS, a run loop can be attached to a NSThread . Its role is to ensure that its NSThread is busy when there is work to do and at rest when there is none. The main thread automatically launches its run loop at the application launch.


1 Answers

Use the Ember.run.schedule method:

 Ember.run.schedule(queue[, context], callback[, *args]);

Here, queue is the run-loop queue (e.g. 'actions'), and callback is the function you want executed. For example:

 Ember.run.schedule('actions', function() {
   console.log('I run at the end of the current runloop');
 });

Relatedly, to prevent the function from running multiple times, use Ember.run.once (you may have also seen it referred to as scheduleOnce):

 Ember.run.once([context,] callback[, *args]);

This will run the callback in the 'actions' queue.

(Updated; thanks to @machty for the corrections!)

like image 186
Jo Liss Avatar answered Sep 30 '22 07:09

Jo Liss