Fix ConcurrentModificationExceptions

This commit is contained in:
Shadowfacts 2021-02-17 22:31:48 -05:00
parent 6a06ef6ae0
commit 7034ce11ef
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 9 additions and 9 deletions

View File

@ -161,12 +161,11 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL),
private fun finishPendingRequests() {
if (world!!.isClient) return
if (pendingRequests.isEmpty()) return
for (request in pendingRequests) {
if (request.isFinishable(counter)) {
stackLocateRequestCompleted(request)
}
}
val finishable = pendingRequests.filter { it.isFinishable(counter) }
// stackLocateRequestCompleted removes the object from pendingRequests
finishable.forEach(::stackLocateRequestCompleted)
}
fun addObserver() {

View File

@ -72,9 +72,10 @@ interface NetworkStackDispatcher<Insertion: NetworkStackDispatcher.PendingInsert
fun <Self, Insertion: NetworkStackDispatcher.PendingInsertion<Insertion>> Self.finishTimedOutPendingInsertions() where Self: BlockEntity, Self: NetworkStackDispatcher<Insertion> {
if (world!!.isClient) return
if (pendingInsertions.isEmpty()) return
for (insertion in pendingInsertions) {
if (!insertion.isFinishable(this)) continue
finishInsertion(insertion)
}
val finishable = pendingInsertions.filter { it.isFinishable(this) }
// finishInsertion removes the object from pendingInsertions
finishable.forEach(::finishInsertion)
// todo: if a timed-out insertion can't be finished, we should probably retry after some time (exponential backoff?)
}