sanpwc commented on code in PR #1183: URL: https://github.com/apache/ignite-3/pull/1183#discussion_r991575814
########## modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java: ########## @@ -84,6 +84,8 @@ public interface IgniteTransactions { /** * Executes a closure within a transaction. * + * <p>Please make sure all asynchronous operations are enlisted into the transaction before returning from the callback. Review Comment: I'm sure that user won't understand this. I don't even believe that user knows what enlist means. I'd rather enforce user with javadoc to use only sync operations or anync ones with joins or gets. ########## modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java: ########## @@ -130,4 +132,22 @@ default <T> T runInTransaction(Function<Transaction, T> clo) throws TransactionE throw t; } } + + /** + * Executes a closure within a transaction asynchronously. + * + * <p>A returned future must be the last in the asynchronous chain. This means all transaction operations happen before the future + * is completed. + * + * <p>If the asynchronous chain resulted in no exception, the commitAsync will be automatically called. + * + * @param clo The closure. + * @param <T> Closure result type. + * @return The result. + */ + default <T> CompletableFuture<T> runInTransactionAsync(Function<Transaction, CompletableFuture<T>> clo) { + // Rollback is expected to be called by the failure handling code Review Comment: What do you mean? It seems as inconsistency to me. As far as I understand you expect user to have op.handle(tx.rollback) within closure despite the fact that sync version of runInTransaction will rollback the tx by her own. ``` default <T> T runInTransaction(Function<Transaction, T> clo) throws TransactionException { Transaction tx = begin(); try { T ret = clo.apply(tx); System.out.println("!!!: Before commit"); tx.commit(); return ret; } catch (Throwable t) { try { tx.rollback(); // Try rolling back on user exception. } catch (Exception e) { t.addSuppressed(e); } throw t; } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org