Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withLocalTx getting a supplyer task and returning the result #25

Closed
JanWiemer opened this issue Sep 2, 2021 · 1 comment
Closed
Assignees

Comments

@JanWiemer
Copy link
Owner

As far as I understand it, there are two general ways for running transactions:

// Option 1
...
JacisLocalTransaction tx = container.beginLocalTransaction();
// Do work
tx.commit();

...

// Option 2
container.withLocalTx(() -> {...});

If I'm not mistaken, using option 1 would not result in a rollback being executed if an exception occurs in my block of work, while a rollback would be attempted when using option 2 and exception occurs.
Assuming this is the case, wouldn't it make sense to offer something like public <T> T withLocalTx(Supplier<T> task) alongside the existing public void withLocalTx(Runnable task)? I often find myself in lengthy transactions that in the end produce some value which I want to return.
Not sure if the above is a feature request or if I'm just missing something...

Originally posted by @fullben in #19

@JanWiemer
Copy link
Owner Author

will be includes in version 2.0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant