Sha256: b70048d15dc04590081295c373962500475578e4be21418fd1da5da436026580

Contents?: true

Size: 961 Bytes

Versions: 32

Compression:

Stored size: 961 Bytes

Contents

(angular => {
  'use strict';

  class LockService {

    constructor() {
      this._locks = {};
    }

    attemptAcquire(lock) {
      if(this._locks[lock]) {
        return false;
      } else {
        this._locks[lock] = true;
        return true;
      }
    }

    release(lock) {
      delete this._locks[lock];
    }

    tryWithLockAsync(lock, criticalSection) {
      if(this.attemptAcquire(lock)) {
        try {
          this._locks[lock] = true;
          return criticalSection(this.release.bind(this, lock));
        } catch (e) {
          this.release(lock);
          throw e;
        }
      }
    }

    tryWithLock(lock, criticalSection) {
      if(this.attemptAcquire(lock)) {
        try {
          this._locks[lock] = true;
          return criticalSection();
        } finally {
          this.release(lock);
        }
      }
    }
  }

  angular.module('alephServices.lockService', []).service('$lock', LockService);
}(angular));

Version data entries

32 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.9.pre.dev app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.4.8 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.8 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.4.7 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.4.7 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.4 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.4 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.4.2 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.2 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.4.1 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.4.1 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.3.0 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.3.0 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.2.0 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.2.0 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.1.0 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.1.0 app/assets/javascripts/angular/services/lib/lock_service.js.es6
aleph_analytics-0.0.6 public/assets/angular/services/lib/lock_service.js-32eb33fda9c27fb5643b25c63099b52c.es6
aleph_analytics-0.0.6 app/assets/javascripts/angular/services/lib/lock_service.js.es6