I want to defer an operation until all bindings have flushed and the current runloop has finished. How do I do that?
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.
Run the runloop in the default mode. The run loop can be stopped by calling Stop().
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.
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.
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!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With