From bf1d224d6409fabff43ea2e2b1664fe4c80afcc0 Mon Sep 17 00:00:00 2001 From: zimski Date: Wed, 1 Jul 2015 11:29:32 +0200 Subject: [PATCH] Add zookeeper sync api call --- lib/client.js | 18 ++++++++++++++++++ package.json | 2 +- test/client.test.js | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 228460b..22c864c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -602,7 +602,25 @@ ZKClient.prototype.unlink = function unlink(p, options, callback) { }); }; +ZKClient.prototype.sync = function sync(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)); + } + log.trace({path: p}, 'sync: done'); + return (callback(err)); + }); +}; ZKClient.prototype.update = function update(p, object, options, callback) { assertString('path', p); assertObject('object', object); diff --git a/package.json b/package.json index 98deccd..cd6a1a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/client.test.js b/test/client.test.js index 209e07b..ba3165b 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -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) {