src/modules/guiEngine/queue.js
/*
   * Add a job to the queue.
   */
Add a job to the queue.
Add a job to the queue .
function add(desc, site, fn) {
    return $q.fromNode(function(cb) {
      var siteName = site.name;
      _hds[siteName] = _hds[siteName] || Promise.resolve();
      _hds[siteName] = _hds[siteName].then(function() {
        if (!_stopFlag) {
          _currents[siteName] = {
            title: desc,
            message: null,
            fn: fn
          };
          var update = function(message) {
            if (_currents[siteName]) {
              _currents[siteName].message = message;
            }
          };
          return $q.try(function() {
            return fn(update);
          });
        }
      })
      .finally(function() {
        _currents[siteName] = null;
      })
      .then(function() {
        cb();
      })
      .catch(function(err) {
        cb(err);
        return errorService.report(err);
      });
    });
  }
function add ( desc , site , fn ) { return $q . fromNode ( function ( cb ) { var siteName = site . name ; _hds [ siteName ] = _hds [ siteName ] || Promise . resolve ( ) ; _hds [ siteName ] = _hds [ siteName ] . then ( function ( ) { if ( ! _stopFlag ) { _currents [ siteName ] = { title : desc , message : null , fn : fn } ; var update = function ( message ) { if ( _currents [ siteName ] ) { _currents [ siteName ] . message = message ; } } ; return $q . try ( function ( ) { return fn ( update ) ; } ) ; } } ) . finally ( function ( ) { _currents [ siteName ] = null ; } ) . then ( function ( ) { cb ( ) ; } ) . catch ( function ( err ) { cb ( err ) ; return errorService . report ( err ) ; } ) ; } ) ; }
Add a job to the queue.
Add a job to the queue .
// Create new promise to signal when this added queue job is done. // Add to end of promise chain. // Set current job. // Update function to update current job's message. // Run function. // Set current job back to null. // Signal job is done. // Make sure errors get reported to the error service. // Signal job is done with an error.