Authored by 郝肖肖

'flx'

... ... @@ -14,7 +14,7 @@ const _createClient = (server) => new Promise((resolve, reject) => {
setTimeout(() => {
!isServerStart && reject({message: 'Failed to authenticate with the server.', code: -1});
}, 5000);
}, 8000);
client.connect();
});
... ... @@ -32,18 +32,16 @@ const _exists = (client, path) => new Promise((resolve, reject) => {
const exists = (server, path) => new Promise((resolve, reject) => {
return _createClient(server).then(client => {
_exists(client, path).then(stat => {
return _exists(client, path).then(stat => {
client.close();
resolve(stat);
});
}).catch(state => {
reject(state);
});
}).catch(reject);
});
const creator = (server, path, value, iscover) => new Promise((resolve, reject) => {
return _createClient(server).then(client => {
_exists(client, path).then(stat => {
return _exists(client, path).then(stat => {
if (stat && iscover) {
client.setData(path, new Buffer(value.toString()), function(err, data, stat) {
client.close();
... ... @@ -51,7 +49,6 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject)
console.log('update path %s data error');
resolve(false);
} else {
console.log('path %s data change to', path, value);
resolve(true);
}
});
... ... @@ -71,14 +68,12 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject)
});
}
});
}).catch(state => {
reject(state);
});
}).catch(reject);
});
const getter = (server, path) => new Promise((resolve, reject) => {
return _createClient(server).then(client => {
_exists(client, path).then(stat => {
return _exists(client, path).then(stat => {
if (stat) {
client.getData(
path,
... ... @@ -98,14 +93,12 @@ const getter = (server, path) => new Promise((resolve, reject) => {
resolve();
}
});
}).catch(state => {
reject(state);
});
}).catch(reject);
});
const setter = (server, path, value) => new Promise((resolve, reject) => {
return _createClient(server).then(client => {
_exists(client, path).then(stat => {
return _exists(client, path).then(stat => {
if (stat) {
client.setData(path, new Buffer(val.toString()), function(err, data, stat) {
client.close();
... ... @@ -121,15 +114,13 @@ const setter = (server, path, value) => new Promise((resolve, reject) => {
resolve(false);
}
});
}).catch(state => {
reject(state);
});
}).catch(reject);
});
const remove = (server, path) => new Promise((resolve, reject) => {
return _createClient(server).then(client => {
_exists(client, path).then(stat => {
return _exists(client, path).then(stat => {
if (stat) {
client.remove(path, function(err) {
client.close();
... ... @@ -140,9 +131,7 @@ const remove = (server, path) => new Promise((resolve, reject) => {
resolve(false);
}
});
}).catch(state => {
reject(state);
});
}).catch(reject);
});
... ...