Skip to content

Commit

Permalink
Add zookeeper sync api call
Browse files Browse the repository at this point in the history
  • Loading branch information
zimski committed Jul 1, 2015
1 parent 4bcf6f7 commit 6fe466e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,26 @@ ZKClient.prototype.unlink = function unlink(p, options, callback) {
});
};

ZKClient.prototype.sync = function get(p, callback) {
assertString('path', p);
assertFunction('callback', callback);

var log = this.log;
var zk = this.zk;

log.trace({path: p}, 'sync: entered');
zk.a_sync(path.normalize(p), function (rc, msg) {
if (rc !== 0) {
var err = new ZKError(rc, msg);
log.trace({path: p, err: err}, 'sync: error');
return (callback(err));
}
console.log("##################### ", msg);

log.trace({path: p}, 'sync: done');
return (callback(err));
});
};
ZKClient.prototype.update = function update(p, object, options, callback) {
assertString('path', p);
assertObject('object', object);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bunyan": "0.11.0",
"node-uuid": "1.3.3",
"vasync": "1.3.1",
"zookeeper": "git://github.com/mcavage/node-zookeeper.git#8a28f8c"
"zookeeper": "git://github.com/fasterize/node-zookeeper.git#9cd98a4217d0e8386d08a465c7818af9935e1d03"
},
"devDependencies": {
"cover": "0.2.8",
Expand Down
15 changes: 15 additions & 0 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ test('update', function (t) {
});
});

test('sync', function (t) {
ZK.create(FILE, function (err) {
t.ifError(err);
var obj = {
hello: 'world'
};
ZK.sync(FILE, function (err2) {
t.ifError(err2);
ZK.get(FILE, function (err3, obj2) {
t.ifError(err3);
t.end();
});
});
});
});

test('unlink', function (t) {
ZK.create(FILE, function (err) {
Expand Down

0 comments on commit 6fe466e

Please sign in to comment.