From ca3e4a9a0513c33f9d642baa91df73e5aa158e9e Mon Sep 17 00:00:00 2001 From: Jae Date: Wed, 13 Jul 2011 15:27:49 +0100 Subject: [PATCH] callback function to notify that fetchInBatch is finished --- examples/test.js | 2 ++ node-hive.js | 7 ++++--- package.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/test.js b/examples/test.js index 0784b8a..b01d586 100644 --- a/examples/test.js +++ b/examples/test.js @@ -11,6 +11,8 @@ var i = 1; hive.fetchInBatch(5, "SELECT * FROM weather_data where dated = '2011-07-02' limit 12", function(err, data) { console.log("SELECT * FROM weather_data where dated = '2011-07-02' limit 12"); console.log(i++ + "th data:", data.toTSV()); +}, function() { + console.log("fetchInBatch completed") }); hive.execute("DESCRIBE weather_data", function(err, data) { diff --git a/node-hive.js b/node-hive.js index 52633d1..dbb3380 100644 --- a/node-hive.js +++ b/node-hive.js @@ -70,17 +70,18 @@ var hiveClient = function(config) { }); }, - fetchInBatch: function(batchSize, query, onCompletion) { - connect(onCompletion, function(client) { + fetchInBatch: function(batchSize, query, onBatchCompletion, onCompletion) { + connect(onBatchCompletion, function(client) { client.execute(query, function() { client.getSchema(function(schema) { var fetchBatch = function() { client.fetchN(batchSize, function(data) { if(data.length > 0) { - onCompletion(null, ResultSet.create(data, schema)); + onBatchCompletion(null, ResultSet.create(data, schema)); process.nextTick(fetchBatch); } else { client.closeConnection(); + if (onCompletion) onCompletion(null, null); } }); }; diff --git a/package.json b/package.json index ae84994..5824f88 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "contributors":["Jae Lee ", "Antonio Terreno ", "Andy Kent"], "name": "node-hive", "description": "Node Hive Client Library", - "version": "0.0.4", + "version": "0.0.5", "homepage": "https://github.com/forward/node-hive", "repository": { "type": "git",