1 define([], function () {
4 function SyncService($timeout){
7 var SyncObject = function () {
8 this.runningRequests = [];
12 this.spawnRequest = function (digest) {
13 var id = digest + (this.reqId++).toString();
14 this.runningRequests.push(id);
15 //console.debug('adding request ',id,' total running requests = ',this.runningRequests);
19 this.removeRequest = function (id) {
20 var index = this.runningRequests.indexOf(id);
23 this.runningRequests.splice(index, 1);
24 //console.debug('removing request ',id,' remaining requests = ',this.runningRequests);
26 console.warn('cannot remove request', id, 'from', this.runningRequests, 'index is', index);
30 this.waitFor = function (callback) {
32 processes = this.runningRequests.length,
35 if (processes > 0 && self.timeElapsed < timeout) {
36 // console.debug('waitin on',processes,'processes',this.runningRequests);
37 $timeout(function () {
38 self.timeElapsed = self.timeElapsed + t;
39 self.waitFor(callback);
48 generateObj: function () {
49 return new SyncObject();
54 SyncService.$inject=['$timeout'];