src code

class ActiveSupport.CallbackQueue

Description

Allows for the execution of callbacks in the order they are registered.

var queue = new ActiveSupport.CallbackQueue(function(){
    console.log('Callback queue empty.');
});
new ActiveSupport.Request(url,{
    onComplete: queue.push(function(){
        console.log('Ajax Request finished.');
    })
});
var callback_two = queue.push(function(){
    console.log('"callback_two" called.');
});
callback_two();
var callback_three = queue.push(function(){
    console.log('"callback_three" called.');
});
callback_three();

Ajax callback finishes after callback_two and callback_three, but output to the console would still be:

//Ajax Request finished.
//"callback_two" called.
//"callback_three" called.
//Callback queue empty.

Note that ActiveSupport.CallbackQueue will only function if the first callback added will be called asynchronously (as a result of an Ajax request or setTimeout call).

Class properties

Instance methods