VanDalkvist
7/13/2017 - 1:29 PM

Miss execution if another is processing

Miss execution if another is processing

function _missExecutionIfAnotherIsProcessing(action) {
    return function () {
      if (action.busy) {
        logger.debug("Missing new execution. Another instance is processing now.");
        return Q.when(action.waiting);
      }

      action.busy = true;
      action.waiting = action.apply(undefined, Array.prototype.slice.call(arguments)).then(function (res) {
        action.busy = false;
        return res;
      });
      return action.waiting;
    };
  }
  
var loadChangesAction = _missExecutionIfAnotherIsProcessing(_loadChanges);