aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/node
diff options
context:
space:
mode:
authorGravatar Michael Lumish <mlumish@google.com>2016-10-20 16:40:59 -0700
committerGravatar GitHub <noreply@github.com>2016-10-20 16:40:59 -0700
commit13905ee9bbaca90061a3327f92673658d67ecba1 (patch)
tree95114cfc8dd0baecc2137124ef2a6650f54d8fd1 /examples/node
parent9243c74868dbf581a98f7799e71f29cd1d55d79f (diff)
parent1647097d40b2826597356671fd6fd8b80492ee46 (diff)
Merge pull request #7967 from p16/node-example-add-return-after-callback-witih-error
Nodejs examples: add return after calling callback(err)
Diffstat (limited to 'examples/node')
-rw-r--r--examples/node/dynamic_codegen/route_guide/route_guide_client.js7
-rw-r--r--examples/node/static_codegen/route_guide/route_guide_client.js7
2 files changed, 12 insertions, 2 deletions
diff --git a/examples/node/dynamic_codegen/route_guide/route_guide_client.js b/examples/node/dynamic_codegen/route_guide/route_guide_client.js
index 775b9addbf..b7550b201a 100644
--- a/examples/node/dynamic_codegen/route_guide/route_guide_client.js
+++ b/examples/node/dynamic_codegen/route_guide/route_guide_client.js
@@ -55,6 +55,7 @@ function runGetFeature(callback) {
function featureCallback(error, feature) {
if (error) {
callback(error);
+ return;
}
if (feature.name === '') {
console.log('Found no feature at ' +
@@ -117,13 +118,17 @@ function runRecordRoute(callback) {
string: 'db_path'
});
fs.readFile(path.resolve(argv.db_path), function(err, data) {
- if (err) callback(err);
+ if (err) {
+ callback(err);
+ return;
+ }
var feature_list = JSON.parse(data);
var num_points = 10;
var call = client.recordRoute(function(error, stats) {
if (error) {
callback(error);
+ return;
}
console.log('Finished trip with', stats.point_count, 'points');
console.log('Passed', stats.feature_count, 'features');
diff --git a/examples/node/static_codegen/route_guide/route_guide_client.js b/examples/node/static_codegen/route_guide/route_guide_client.js
index ecde78616b..e16de44a1a 100644
--- a/examples/node/static_codegen/route_guide/route_guide_client.js
+++ b/examples/node/static_codegen/route_guide/route_guide_client.js
@@ -56,6 +56,7 @@ function runGetFeature(callback) {
function featureCallback(error, feature) {
if (error) {
callback(error);
+ return;
}
var latitude = feature.getLocation().getLatitude();
var longitude = feature.getLocation().getLongitude();
@@ -115,7 +116,10 @@ function runRecordRoute(callback) {
string: 'db_path'
});
fs.readFile(path.resolve(argv.db_path), function(err, data) {
- if (err) callback(err);
+ if (err) {
+ callback(err);
+ return;
+ }
// Transform the loaded features to Feature objects
var feature_list = _.map(JSON.parse(data), function(value) {
var feature = new messages.Feature();
@@ -131,6 +135,7 @@ function runRecordRoute(callback) {
var call = client.recordRoute(function(error, stats) {
if (error) {
callback(error);
+ return;
}
console.log('Finished trip with', stats.getPointCount(), 'points');
console.log('Passed', stats.getFeatureCount(), 'features');