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