Showing
1 changed file
with
6 additions
and
5 deletions
@@ -19,8 +19,8 @@ const exists = (server, path) => new Promise((resolve, reject) => { | @@ -19,8 +19,8 @@ const exists = (server, path) => new Promise((resolve, reject) => { | ||
19 | 19 | ||
20 | client.once('connected', function () { | 20 | client.once('connected', function () { |
21 | _exists(client, path).then(stat => { | 21 | _exists(client, path).then(stat => { |
22 | - resolve(stat); | ||
23 | client.close(); | 22 | client.close(); |
23 | + resolve(stat); | ||
24 | }); | 24 | }); |
25 | }); | 25 | }); |
26 | 26 | ||
@@ -34,6 +34,7 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | @@ -34,6 +34,7 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | ||
34 | _exists(client, path).then(stat => { | 34 | _exists(client, path).then(stat => { |
35 | if (stat && iscover) { | 35 | if (stat && iscover) { |
36 | client.setData(path, new Buffer(value.toString()), function(err, data, stat) { | 36 | client.setData(path, new Buffer(value.toString()), function(err, data, stat) { |
37 | + client.close(); | ||
37 | if (err) { | 38 | if (err) { |
38 | console.log('update path %s data error'); | 39 | console.log('update path %s data error'); |
39 | resolve(false); | 40 | resolve(false); |
@@ -43,9 +44,11 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | @@ -43,9 +44,11 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | ||
43 | } | 44 | } |
44 | }); | 45 | }); |
45 | } else if (stat) { | 46 | } else if (stat) { |
47 | + client.close(); | ||
46 | resolve(true); | 48 | resolve(true); |
47 | } else { | 49 | } else { |
48 | client.mkdirp(path, new Buffer(value), (err, path) => { | 50 | client.mkdirp(path, new Buffer(value), (err, path) => { |
51 | + client.close(); | ||
49 | if (err) { | 52 | if (err) { |
50 | console.log('Node %s create err', path, err.stack); | 53 | console.log('Node %s create err', path, err.stack); |
51 | resolve(false); | 54 | resolve(false); |
@@ -55,7 +58,6 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | @@ -55,7 +58,6 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) | ||
55 | } | 58 | } |
56 | }); | 59 | }); |
57 | } | 60 | } |
58 | - client.close(); | ||
59 | }); | 61 | }); |
60 | }); | 62 | }); |
61 | 63 | ||
@@ -76,7 +78,6 @@ const getter = (server, path) => new Promise((resolve, reject) => { | @@ -76,7 +78,6 @@ const getter = (server, path) => new Promise((resolve, reject) => { | ||
76 | } | 78 | } |
77 | 79 | ||
78 | client.close(); | 80 | client.close(); |
79 | - | ||
80 | resolve(data && data.toString('utf8')); | 81 | resolve(data && data.toString('utf8')); |
81 | } | 82 | } |
82 | ) | 83 | ) |
@@ -99,6 +100,7 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { | @@ -99,6 +100,7 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { | ||
99 | _exists(client, path).then(stat => { | 100 | _exists(client, path).then(stat => { |
100 | if (stat) { | 101 | if (stat) { |
101 | client.setData(path, new Buffer(val.toString()), function(err, data, stat) { | 102 | client.setData(path, new Buffer(val.toString()), function(err, data, stat) { |
103 | + client.close(); | ||
102 | if (err) { | 104 | if (err) { |
103 | console.log('update path %s data error'); | 105 | console.log('update path %s data error'); |
104 | resolve(false); | 106 | resolve(false); |
@@ -106,10 +108,9 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { | @@ -106,10 +108,9 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { | ||
106 | console.log('path %s data change to', path, value); | 108 | console.log('path %s data change to', path, value); |
107 | resolve(true); | 109 | resolve(true); |
108 | } | 110 | } |
109 | - | ||
110 | - client.close(); | ||
111 | }); | 111 | }); |
112 | } else { | 112 | } else { |
113 | + client.close(); | ||
113 | resolve(false); | 114 | resolve(false); |
114 | } | 115 | } |
115 | }); | 116 | }); |
-
Please register or login to post a comment