@@ -31,6 +31,13 @@ To get the latest stable release omit `@next` part altogether or use `@latest` i
31
31
``` javascript
32
32
var neo4j = require (' neo4j-driver' ).v1 ;
33
33
```
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.
34
41
35
42
## Include in web browser
36
43
@@ -46,13 +53,33 @@ This will make a global `neo4j` object available, where you can access the `v1`
46
53
var driver = neo4j .driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
47
54
```
48
55
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
+
49
64
## Usage examples
50
65
51
66
``` javascript
52
67
53
68
// 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.
54
70
var driver = neo4j .driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
55
71
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
+
56
83
// Create a session to run Cypher statements in.
57
84
// Note: Always make sure to close sessions when you are done using them!
58
85
var session = driver .session ();
@@ -122,8 +149,18 @@ if (success) {
122
149
console .log (' rolled back' );
123
150
tx .rollback ();
124
151
}
152
+
153
+ // Close the driver when application exits
154
+ driver .close ();
125
155
```
126
156
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
+
127
164
## Building
128
165
129
166
npm install
0 commit comments