Skip to content

Commit

Permalink
actually fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Sep 16, 2023
1 parent 6bdd4bc commit 187da88
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ 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();
try (Transaction simulateTransaction = Transaction.openNested(transaction)) {
return moveResources(storage, resource, maxAmount, simulateTransaction);
}
}
return ret;

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

0 comments on commit 187da88

Please sign in to comment.