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

usingWhen factory issue with reactor-core 3.4.17 #23

Open
srikanthpolineni opened this issue May 27, 2022 · 1 comment
Open

usingWhen factory issue with reactor-core 3.4.17 #23

srikanthpolineni opened this issue May 27, 2022 · 1 comment

Comments

@srikanthpolineni
Copy link

UsingWhen factory method declaration got changed in reactor-core 3.4.17. Source needs to update with

@Test
    public void usingWhenExample() throws InterruptedException {
        Flux.usingWhen(
                Transaction.beginTransaction(),
                transaction -> transaction.insertRows(Flux.just("A", "B")),
                Transaction::commit,
                (transaction, throwable) -> Mono.empty(), // <<== extra parameter
                Transaction::rollback
        ).subscribe(
                d -> log.info("onNext: {}", d),
                e -> log.info("onError: {}", e.getMessage()),
                () -> log.info("onComplete")
        );

        Thread.sleep(1000);
    }
@Linukso1D
Copy link

Hi there I would say your extra parameter for the asyncError was wrong because it should perform the rollback if an exception occurs at transaction.insertRows
From the other side if an error occurs at commit - rollback will not be called and will be passed to a subscriber

   Flux.usingWhen(
                Transaction.beginTransaction(),
                transaction -> transaction.insertRows(Flux.just("A", "B")),
                transaction -> transaction.commit().onErrorResume(ex -> transaction.rollback().then(Mono.error(ex))), // this approach is able to catch an error inside the commit block. PS
                (transaction, throwable) -> transaction.rollback(),  // rollback on error
                Transaction::rollback
        )

I would be happy to look at some shorter forms for tx::commit but for now I don't know how to catch an error for commit block in some pretty way.

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

No branches or pull requests

2 participants