Skip to content

Commit

Permalink
Merge branch 'master' into 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Sep 16, 2023
2 parents 3c32161 + ed942f8 commit 77ebad3
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ public interface StorageInteraction<T> {
long moveResources(Storage<T> storage, T resource, long maxAmount, TransactionContext transaction);

default long moveResources(Storage<T> storage, T resource, long maxAmount, TransactionContext transaction, boolean simulate) {
TransactionContext transactionContext = transaction;
if (simulate)
transactionContext = transaction.openNested();

long ret = moveResources(storage, resource, maxAmount, transactionContext);
if (simulate) {
// can safely cast to transaction because openNested returns a Transaction
// parent transaction should never be committed or aborted by any means
var transaction1 = (Transaction) transaction;
transaction1.close();
// closes this automatically
// check functionality of AutoCloseable class
try (Transaction simulateTransaction = Transaction.openNested(transaction)) {
return moveResources(storage, resource, maxAmount, simulateTransaction);
}
}
return ret;

return moveResources(storage, resource, maxAmount, transaction);
}
}

0 comments on commit 77ebad3

Please sign in to comment.