Skip to content

Introduce the ability of awaiting for eager beginning a Transaction #870

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

Merged
merged 3 commits into from
Feb 14, 2022

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Feb 8, 2022

The current implementation of session.beginTransaction does not wait the success message. This kind of behaviour can cause future calls to run and commit because of non-reported errors during the begin.

For solving this issue, the transaction object return by the session.beginTransaction was changed to TransactionPromise. This new type holds all the behaviours from a Transaction and also holds the promise for the beginned transaction. This way, the caller can eagerly eager check the transaction begin and at the same type keep the API existing in the current codebase.

Eager Mode:

const tx = await session.beginTransaction() // waits for begin result
const result = await tx.run('RETURN 1') // only throws RUN related errors, not reachable when begin fails

Lazy Mode:

const tx = session.beginTransaction() // no wait, any begin errors will be thrown
const result = await tx.run('RETURN 1') // throws BEGIN and RUN related errors

@bigmontz bigmontz force-pushed the 5.0-implementing-eager-begin branch from a0164c6 to a90a7c0 Compare February 8, 2022 16:22
@bigmontz
Copy link
Contributor Author

bigmontz commented Feb 8, 2022

Depends on: neo4j-drivers/testkit#397

@bigmontz bigmontz force-pushed the 5.0-implementing-eager-begin branch 2 times, most recently from 7237267 to ffe245e Compare February 9, 2022 11:20
@bigmontz bigmontz marked this pull request as ready for review February 10, 2022 11:13
@fbiville fbiville self-requested a review February 10, 2022 16:09
@bigmontz bigmontz force-pushed the 5.0-implementing-eager-begin branch from 788a24e to 9ec34af Compare February 14, 2022 10:20
@bigmontz bigmontz merged commit 00d821d into neo4j:5.0 Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants