Skip to content

Commit 051a28a

Browse files
committed
Add zookeeper sync api call
1 parent 4bcf6f7 commit 051a28a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/client.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,25 @@ ZKClient.prototype.unlink = function unlink(p, options, callback) {
602602
});
603603
};
604604

605+
ZKClient.prototype.sync = function get(p, callback) {
606+
assertString('path', p);
607+
assertFunction('callback', callback);
608+
609+
var log = this.log;
610+
var zk = this.zk;
611+
612+
log.trace({path: p}, 'sync: entered');
613+
zk.a_sync(path.normalize(p), function (rc, msg) {
614+
if (rc !== 0) {
615+
var err = new ZKError(rc, msg);
616+
log.trace({path: p, err: err}, 'sync: error');
617+
return (callback(err));
618+
}
605619

620+
log.trace({path: p}, 'sync: done');
621+
return (callback(err));
622+
});
623+
};
606624
ZKClient.prototype.update = function update(p, object, options, callback) {
607625
assertString('path', p);
608626
assertObject('object', object);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"bunyan": "0.11.0",
1010
"node-uuid": "1.3.3",
1111
"vasync": "1.3.1",
12-
"zookeeper": "git://github.com/mcavage/node-zookeeper.git#8a28f8c"
12+
"zookeeper": "git://github.com/fasterize/node-zookeeper.git#9cd98a4217d0e8386d08a465c7818af9935e1d03"
1313
},
1414
"devDependencies": {
1515
"cover": "0.2.8",

test/client.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@ test('update', function (t) {
174174
});
175175
});
176176

177+
test('sync', function (t) {
178+
ZK.create(FILE, function (err) {
179+
t.ifError(err);
180+
var obj = {
181+
hello: 'world'
182+
};
183+
ZK.sync(FILE, function (err2) {
184+
t.ifError(err2);
185+
ZK.get(FILE, function (err3, obj2) {
186+
t.ifError(err3);
187+
t.end();
188+
});
189+
});
190+
});
191+
});
177192

178193
test('unlink', function (t) {
179194
ZK.create(FILE, function (err) {

0 commit comments

Comments
 (0)