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:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user