1 define([], function () {
4 function SyncService($timeout){
8 generateObj: function () {
9 return new SyncObject();
16 * Base synchronization object
19 function SyncObject() {
20 this.runningRequests = [];
24 this.spawnRequest = function (digest) {
25 var id = digest + (this.reqId++).toString();
26 this.runningRequests.push(id);
27 // console.debug('adding request ',id,' total running requests = ',this.runningRequests);
31 this.removeRequest = function (id) {
32 var index = this.runningRequests.indexOf(id);
35 this.runningRequests.splice(index, 1);
36 // console.debug('removing request ',id,' remaining requests = ',this.runningRequests);
38 console.warn('cannot remove request', id, 'from', this.runningRequests, 'index is', index);
42 this.waitFor = function (callback) {
44 processes = this.runningRequests.length,
47 if (processes > 0 && self.timeElapsed < timeout) {
48 // console.debug('waitin on',processes,'processes',this.runningRequests);
49 $timeout(function () {
50 self.timeElapsed = self.timeElapsed + t;
51 self.waitFor(callback);
60 SyncService.$inject = ['$timeout'];