withLock(callback, critical) {
    if(this._isLocked)
      throw new Error('Current operation has not been finished.');

    var self = this;
    try {
      this._isLocked = true;
      var result = callback().then(function(result) {
        self._isLocked = false;
        return result;
      }, function(e) {
        if (!critical)
          self._isLocked = false;
        throw e;
      });

      this._readyPromise = result.then(function() {
        return self;
      }, function(e) {
        if (!critical)
          return self;
        throw e;
      });

      return result;
    } catch (e) {
      if (critical) {
        this._readyPromise = Promise.reject(e);
      } else {
        this._isLocked = false;
      }
      throw e;
    }
  }
/**
   * Try to aquire an exclusive lock and executes the given callback.
   * @param {util.Lockable~callback} callback The exclusive operation to execute
   * @param {boolean} [critical=false] Indicates if the operation is critical. If the operation is critical and the
   * operation fails, then the lock will not be released
   * @return {Promise<util.Lockable>} A promise
   * @throws {Error} If the lock can't be aquired
   * @protected
   */
Try to aquire an exclusive lock and executes the given callback.
@param {util.Lockable~callback} callback The exclusive operation to execute
@param {boolean} [critical=false] Indicates if the operation is critical. If the operation is critical and the
operation fails, then the lock will not be released
@return {Promise} A promise
@throws {Error} If the lock can't be aquired
@protected
Try to aquire an exclusive lock and executes the given callback . @param { util . Lockable~callback } callback The exclusive operation to execute @param { boolean } [ critical = false ] Indicates if the operation is critical . If the operation is critical and the operation fails then the lock will not be released @return { Promise } A promise @throws { Error } If the lock can ' t be aquired @protected
withLock(callback, critical) {
    if(this._isLocked)
      throw new Error('Current operation has not been finished.');
    var self = this;
    try {
      this._isLocked = true;
      var result = callback().then(function(result) {
        self._isLocked = false;
        return result;
      }, function(e) {
        if (!critical)
          self._isLocked = false;
        throw e;
      });
      this._readyPromise = result.then(function() {
        return self;
      }, function(e) {
        if (!critical)
          return self;
        throw e;
      });
      return result;
    } catch (e) {
      if (critical) {
        this._readyPromise = Promise.reject(e);
      } else {
        this._isLocked = false;
      }
      throw e;
    }
  }
withLock ( callback , critical ) { if ( this . _isLocked ) throw new Error ( 'Current operation has not been finished.' ) ; var self = this ; try { this . _isLocked = true ; var result = callback ( ) . then ( function ( result ) { self . _isLocked = false ; return result ; } , function ( e ) { if ( ! critical ) self . _isLocked = false ; throw e ; } ) ; this . _readyPromise = result . then ( function ( ) { return self ; } , function ( e ) { if ( ! critical ) return self ; throw e ; } ) ; return result ; } catch ( e ) { if ( critical ) { this . _readyPromise = Promise . reject ( e ) ; } else { this . _isLocked = false ; } throw e ; } }
Try to aquire an exclusive lock and executes the given callback.
Try to aquire an exclusive lock and executes the given callback .