Function

Module: @ember/runloop
import { schedule } from '@ember/runloop';
queue
String
The name of the queue to schedule against. Default queues is 'actions'
target
Object
target object to use as the context when invoking a method.
method
String|Function
The method to invoke. If you pass a string it will be resolved on the target object at the time the scheduled item is invoked allowing you to change the target function.
arguments*
Object
Optional arguments to be passed to the queued method.
returns
*
Timer information for use in canceling, see `cancel`.

Adds the passed target/method and any optional arguments to the named queue to be executed at the end of the RunLoop. If you have not already started a RunLoop when calling this method one will be started for you automatically.

At the end of a RunLoop, any methods scheduled in this way will be invoked. Methods will be invoked in an order matching the named queues defined in the queues property.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { schedule } from '@ember/runloop';

schedule('afterRender', this, function() {
  // this will be executed in the 'afterRender' queue
  console.log('scheduled on afterRender queue');
});

schedule('actions', this, function() {
  // this will be executed in the 'actions' queue
  console.log('scheduled on actions queue');
});

// Note the functions will be run in order based on the run queues order.
// Output would be:
//   scheduled on actions queue
//   scheduled on afterRender queue