ionic-core.js
function(lockKey, asyncFunction) {

          var deferred = $q.defer();

          // If the memory lock is set, error out.
          if (memoryLocks[lockKey]) {
            deferred.reject('in_progress');
            return deferred.promise;
          }

          // If there is a stored lock but no memory lock, flag a persistence error
          if (persistenceStrategy.get(lockKey) === 'locked') {
            deferred.reject('last_call_interrupted');
            deferred.promise.then(null, function() {
              persistenceStrategy.remove(lockKey);
            });
            return deferred.promise;
          }

          // Set stored and memory locks
          memoryLocks[lockKey] = true;
          persistenceStrategy.set(lockKey, 'locked');

          // Perform the async operation
          asyncFunction().then(function(successData) {
            deferred.resolve(successData);

            // Remove stored and memory locks
            delete memoryLocks[lockKey];
            persistenceStrategy.remove(lockKey);
          }, function(errorData) {
            deferred.reject(errorData);

            // Remove stored and memory locks
            delete memoryLocks[lockKey];
            persistenceStrategy.remove(lockKey);
          }, function(notifyData) {
            deferred.notify(notifyData);
          });

          return deferred.promise;
        }
function(lockKey, asyncFunction) {

          var deferred = $q.defer();

          // If the memory lock is set, error out.
          if (memoryLocks[lockKey]) {
            deferred.reject('in_progress');
            return deferred.promise;
          }

          // If there is a stored lock but no memory lock, flag a persistence error
          if (persistenceStrategy.get(lockKey) === 'locked') {
            deferred.reject('last_call_interrupted');
            deferred.promise.then(null, function() {
              persistenceStrategy.remove(lockKey);
            });
            return deferred.promise;
          }

          // Set stored and memory locks
          memoryLocks[lockKey] = true;
          persistenceStrategy.set(lockKey, 'locked');

          // Perform the async operation
          asyncFunction().then(function(successData) {
            deferred.resolve(successData);

            // Remove stored and memory locks
            delete memoryLocks[lockKey];
            persistenceStrategy.remove(lockKey);
          }, function(errorData) {
            deferred.reject(errorData);

            // Remove stored and memory locks
            delete memoryLocks[lockKey];
            persistenceStrategy.remove(lockKey);
          }, function(notifyData) {
            deferred.notify(notifyData);
          });

          return deferred.promise;
        }
function ( lockKey , asyncFunction ) { var deferred = $q . defer ( ) ; // If the memory lock is set, error out. if ( memoryLocks [ lockKey ] ) { deferred . reject ( 'in_progress' ) ; return deferred . promise ; } // If there is a stored lock but no memory lock, flag a persistence error if ( persistenceStrategy . get ( lockKey ) === 'locked' ) { deferred . reject ( 'last_call_interrupted' ) ; deferred . promise . then ( null , function ( ) { persistenceStrategy . remove ( lockKey ) ; } ) ; return deferred . promise ; } // Set stored and memory locks memoryLocks [ lockKey ] = true ; persistenceStrategy . set ( lockKey , 'locked' ) ; // Perform the async operation asyncFunction ( ) . then ( function ( successData ) { deferred . resolve ( successData ) ; // Remove stored and memory locks delete memoryLocks [ lockKey ] ; persistenceStrategy . remove ( lockKey ) ; } , function ( errorData ) { deferred . reject ( errorData ) ; // Remove stored and memory locks delete memoryLocks [ lockKey ] ; persistenceStrategy . remove ( lockKey ) ; } , function ( notifyData ) { deferred . notify ( notifyData ) ; } ) ; return deferred . promise ; }
Locks the async call represented by the given promise and lock key.
Only one asyncFunction given by the lockKey can be running at any time.

@param lockKey should be a string representing the name of this async call.
This is required for persistence.
@param asyncFunction Returns a promise of the async call.
@returns A new promise, identical to the one returned by asyncFunction,
but with two new errors: 'in_progress', and 'last_call_interrupted'.
Locks the async call represented by the given promise and lock key . Only one asyncFunction given by the lockKey can be running at any time .