From ff3fec20dd13fade6c03e71aa4d6a00c715ef18c Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 5 Jan 2017 12:08:03 +0100 Subject: [PATCH 1/4] Mention the need to close driver in the readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 95e8b3680..2daaa51ba 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,13 @@ To get the latest stable release omit `@next` part altogether or use `@latest` i ```javascript var neo4j = require('neo4j-driver').v1; ``` +Driver instance should be closed when Node.js application exits: + +```javascript +driver.close(); +``` + +otherwise application shutdown might hang or it might exit with a non-zero exit code. ## Include in web browser @@ -46,6 +53,14 @@ This will make a global `neo4j` object available, where you can access the `v1` var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); ``` +It is not required to explicitly close the driver on a web page. Web browser should gracefully close all open +WebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime +is not the same as the lifetime of the web page: + +```javascript +driver.close(); +``` + ## Usage examples ```javascript From d9fcfdb5e1c56cb47ed1e432bad8b8cf77a7865e Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 5 Jan 2017 12:17:53 +0100 Subject: [PATCH 2/4] Mention ordering of callback invocations in the readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 2daaa51ba..5aecd2379 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,13 @@ if (success) { } ``` +Subscriber API allows following combinations of `onNext`, `onCompleted` and `onError` callback invocations: + * zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked + in this case + * zero or more `onNext` followed by `onError` when operation failed. Callback `onError` might be invoked after + couple `onNext` invocations because records are streamed lazily by the database. `onCompleted` will not be invoked + in this case + ## Building npm install From b6549b65eb2624f354b48e4344e268b906d09fc0 Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 5 Jan 2017 12:27:02 +0100 Subject: [PATCH 3/4] Mention driver callbacks in the readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 5aecd2379..4cd269eb6 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,17 @@ driver.close(); // Create a driver instance, for the user neo4j with password neo4j. var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); +// Register a callback to know if driver creation was successful: +driver.onCompleted = function() { + // proceed with using the driver, it was successfully instantiated +}; + +// Register a callback to know if driver creation failed. +// This could happen due to wrong credentials or database unavailability: +driver.onError = function(error) { + console.log('Driver instantiation failed', error); +}; + // Create a session to run Cypher statements in. // Note: Always make sure to close sessions when you are done using them! var session = driver.session(); From 798ced79569ceebdab15aabb0c32f192993e9da2 Mon Sep 17 00:00:00 2001 From: lutovich Date: Thu, 5 Jan 2017 14:16:12 +0100 Subject: [PATCH 4/4] Add `driver.close()` to the usage example --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4cd269eb6..64ccaa3c7 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ driver.close(); ```javascript // Create a driver instance, for the user neo4j with password neo4j. +// It should be enough to have a single driver per database per application. var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); // Register a callback to know if driver creation was successful: @@ -148,6 +149,9 @@ if (success) { console.log('rolled back'); tx.rollback(); } + +// Close the driver when application exits +driver.close(); ``` Subscriber API allows following combinations of `onNext`, `onCompleted` and `onError` callback invocations: