Update garbage collect algorithm. Fixed some tests appearantly :)
This commit is contained in:
		
							parent
							
								
									8e4cf83330
								
							
						
					
					
						commit
						37ac7787d0
					
				@ -71,6 +71,8 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
      this.gcTimeout = opts.gcTimeout || 5000
 | 
			
		||||
      var os = this
 | 
			
		||||
      function garbageCollect () {
 | 
			
		||||
        return os.whenTransactionsFinished().then(function () {
 | 
			
		||||
          if (os.gc1.length > 0 || os.gc2.length > 0) {
 | 
			
		||||
            return new Promise((resolve) => {
 | 
			
		||||
              os.requestTransaction(function * () {
 | 
			
		||||
                if (os.y.connector != null && os.y.connector.isSynced) {
 | 
			
		||||
@ -81,12 +83,21 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
                  os.gc2 = os.gc1
 | 
			
		||||
                  os.gc1 = []
 | 
			
		||||
                }
 | 
			
		||||
                // TODO: Use setInterval here instead (when garbageCollect is called several times there will be several timeouts..)
 | 
			
		||||
                if (os.gcTimeout > 0) {
 | 
			
		||||
                  os.gcInterval = setTimeout(garbageCollect, os.gcTimeout)
 | 
			
		||||
                }
 | 
			
		||||
                resolve()
 | 
			
		||||
              })
 | 
			
		||||
            })
 | 
			
		||||
          } else {
 | 
			
		||||
            // TODO: see above
 | 
			
		||||
            if (os.gcTimeout > 0) {
 | 
			
		||||
              os.gcInterval = setTimeout(garbageCollect, os.gcTimeout)
 | 
			
		||||
            }
 | 
			
		||||
            return Promise.resolve()
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      this.garbageCollect = garbageCollect
 | 
			
		||||
      if (this.gcTimeout > 0) {
 | 
			
		||||
@ -205,10 +216,12 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
    apply (ops) {
 | 
			
		||||
      for (var key in ops) {
 | 
			
		||||
        var o = ops[key]
 | 
			
		||||
        if (o.id == null || o.id[0] !== this.y.connector.userId) {
 | 
			
		||||
          var required = Y.Struct[o.struct].requiredOps(o)
 | 
			
		||||
          this.whenOperationsExist(required, o)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    /*
 | 
			
		||||
      op is executed as soon as every operation requested is available.
 | 
			
		||||
      Note that Transaction can (and should) buffer requests.
 | 
			
		||||
@ -390,7 +403,7 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    requestTransaction (makeGen/* :any */, callImmediately) {
 | 
			
		||||
      if (true || callImmediately) { // TODO: decide whether this is ok or not..
 | 
			
		||||
      if (false || callImmediately) { // TODO: decide whether this is ok or not..
 | 
			
		||||
        this.waitingTransactions.push(makeGen)
 | 
			
		||||
        if (!this.transactionInProgress) {
 | 
			
		||||
          this.transactionInProgress = true
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user