setter.js 657 Bytes
'usu strict';

import _ from 'lodash';
import zookeeper from 'node-zookeeper-client';

module.exports = (server, path, val) => new Promise((resolve, reject) => {
    const client = zookeeper.createClient(server);

    client.once('connected', function () {
        client.setData(path, new Buffer(val.toString()), function(err, data, stat) {
            if (err) {
                console.log('update path %s data error');
                resolve();
            } else {
                console.log('path %s data change to', path, val);
                resolve(true);
            }
            client.close();
        });
    });

    client.connect();
});