Change execution order to mitigate exception effects

For unknown reasons the "firstItem" is undefined in very rare cases.
By changing the execution order, the drop will still work even if an exception occurs.
This commit is contained in:
Thomas Nordquist
2019-03-19 18:30:29 +01:00
parent 485e1cffae
commit aa8d066fe1

View File

@@ -62,9 +62,11 @@ export class RingBuffer<T extends Lengthwise> {
} }
private dropFirst() { private dropFirst() {
const freedSpace = this.items[this.start].length const firstItem = this.items[this.start]
this.usage -= freedSpace
delete this.items[this.start] delete this.items[this.start]
this.start += 1 this.start += 1
const freedSpace = firstItem.length
this.usage -= freedSpace
} }
} }