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

Fix Driver.onCompleted callback #298

Merged
merged 1 commit into from
Oct 4, 2017
Merged

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented Oct 4, 2017

Setting this callback will now trigger connectivity verification. Provided callback function will be invoked if verification succeeds. When onCompleted callback is not set no verification will happen. This is achieved using getter/setter on onCompleted property.

This callback has previously been broken when session was decoupled from connection.

Removed Driver.onCompleted and Driver.onError from README. These callbacks were introduced specifically for neo4j-browser that needs to verify connectivity and be notified about broken WebSockets. So they were always a "special" not fully thought through part of driver's public API. It is preferable to do connectivity verification by running a dummy query like RETURN 1. Note that it's not always required.

Fixes #234

@lutovich lutovich requested a review from ali-ince October 4, 2017 08:26
Setting this callback will now trigger connectivity verification.
Provided callback function will be invoked if verification succeeds.
When `onCompleted` callback is not set no verification will happen.
This is achieved using getter/setter on `onCompleted` property.

This callback has previously been broken when session was decoupled
from connection.

Removed `Driver.onCompleted` and `Driver.onError` from README. These
callbacks were introduced specifically for neo4j-browser that needs to
verify connectivity and be notified about broken WebSockets. So they
were always a "special" not fully thought through part of driver's
public API. It is preferable to do connectivity verification by running
a dummy query like `RETURN 1`. Note that it's not always required.
@lutovich lutovich force-pushed the 1.5-driver-callbacks branch from 984f034 to a621f58 Compare October 4, 2017 08:52
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. One comment though about a confusion.

return this._onCompleted;
}

set onCompleted(callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting an event handler invoking actual verification confused me a bit. What happens if verification fails? Maybe an explicit method verifyConnectivity() returning a promise would be a better option, can be elaborated for upcoming versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed verification will result in Driver.onCompleted not being invoked. Instead Driver.onError will be invoked. I agree, these callbacks are not ideal and rather ugly. That's why they are removed from README. Users can verify connectivity by running a dummy query like RETURN 1. So this fix is only for backwards compatibility.

@ali-ince ali-ince merged commit 0e199f3 into neo4j:1.5 Oct 4, 2017
@lutovich lutovich deleted the 1.5-driver-callbacks branch October 4, 2017 12:23
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