@@ -31,6 +31,13 @@ To get the latest stable release omit `@next` part altogether or use `@latest` i
3131``` javascript
3232var neo4j = require (' neo4j-driver' ).v1 ;
3333```
34+ Driver instance should be closed when Node.js application exits:
35+
36+ ``` javascript
37+ driver .close ();
38+ ```
39+
40+ otherwise application shutdown might hang or it might exit with a non-zero exit code.
3441
3542## Include in web browser
3643
@@ -46,13 +53,33 @@ This will make a global `neo4j` object available, where you can access the `v1`
4653var driver = neo4j .driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
4754```
4855
56+ It is not required to explicitly close the driver on a web page. Web browser should gracefully close all open
57+ WebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime
58+ is not the same as the lifetime of the web page:
59+
60+ ``` javascript
61+ driver .close ();
62+ ```
63+
4964## Usage examples
5065
5166``` javascript
5267
5368// Create a driver instance, for the user neo4j with password neo4j.
69+ // It should be enough to have a single driver per database per application.
5470var driver = neo4j .driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
5571
72+ // Register a callback to know if driver creation was successful:
73+ driver .onCompleted = function () {
74+ // proceed with using the driver, it was successfully instantiated
75+ };
76+
77+ // Register a callback to know if driver creation failed.
78+ // This could happen due to wrong credentials or database unavailability:
79+ driver .onError = function (error ) {
80+ console .log (' Driver instantiation failed' , error);
81+ };
82+
5683// Create a session to run Cypher statements in.
5784// Note: Always make sure to close sessions when you are done using them!
5885var session = driver .session ();
@@ -122,8 +149,18 @@ if (success) {
122149 console .log (' rolled back' );
123150 tx .rollback ();
124151}
152+
153+ // Close the driver when application exits
154+ driver .close ();
125155```
126156
157+ Subscriber API allows following combinations of ` onNext ` , ` onCompleted ` and ` onError ` callback invocations:
158+ * zero or more ` onNext ` followed by ` onCompleted ` when operation was successful. ` onError ` will not be invoked
159+ in this case
160+ * zero or more ` onNext ` followed by ` onError ` when operation failed. Callback ` onError ` might be invoked after
161+ couple ` onNext ` invocations because records are streamed lazily by the database. ` onCompleted ` will not be invoked
162+ in this case
163+
127164## Building
128165
129166 npm install
0 commit comments