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