EMBER WORKSHOP: Backburner simple

Backburner simple

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
<script src="http://aaron.haurwitz.com/scripts/backburner.js"></script>
<div>Online: 
    <span id="online-status"></span>
</div>

JavaScript

(function ($, backburner, global) {
    
// Backburner#run - execute the passed function and flush any deferred actions
// Backburner#defer - defer the passed function to run inside the specified queue
// Backburner#deferOnce - defer the passed function to run inside the specified queue, only execute it once
// Backburner#setTimeout - execute the passed function in a specified amount of time
// Backburner#debounce - execute the passed function in a specified amount of time, reset timer upon additional calls
// Backburner#throttle - rate-limit the passed function for a specified amount of time
// Backburner#cancel - cancel a deferOnce, setTimeout, debounce or throttle  
    
    var Backburner = backburner.Backburner;
  
// This creates a new Backburner instance with four queues.
// When you use Backburner's API to interact with these queues, 
// you are ensured that actions deferred to one queue only occur 
// after all actions in prior queues have been executed. 
    
    var backburner = new Backburner(['network','authentication','database','render']); // add a few queues
    
    var player = {
        isLoggingIn: null,      
        isOnline: true
    }; // create a player model
    
// Backburner#defer
// defer an action to one of the queues.
    
    function sniffNetwork(){
      //backburner.setTimeout('network', alertUser, 3000); // defer the network queue
        backburner.defer('network', 
          function(){
            alertUser('request is in the network queue')
          }); // defer the network queue
        backburner.defer('authentication', 
          function(){
            alertUser('request is in the authentication queue')
          }); // defer the authentication queue
    }
    
    function updateStatus() {
      $('#online-status').text(player.isOnline); // update the DOM
    }
    
    function alertUser(msg) {
      alert(msg);
    }
    
// Backburner#deferOnce
// the action will only be executed once in the flushing of that queue,...