From fd735e248fc7fdfc4df73ff36179f8ea6858d946 Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Wed, 10 Jul 2013 05:06:44 -0500 Subject: [PATCH] Change to callback method --- README.md | 5 ++++- index.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f6a418..9fe0250 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ var Gamedig = require('gamedig'); Gamedig.query({ type: 'minecraft', host: 'mc.example.com', - success: function(state) { + callback: function(state) { if(state.error) console.log("Server is offline"); else console.log(state); } @@ -18,6 +18,9 @@ Gamedig.query({ State Object --- +The callback function is "guaranteed" to be called exactly once, indicating either a query error or timeout +(in the state's error key), or with a state object containg the successful results. + The returned state object may contain some or all of the following keys, depending on what is available from the queried server: diff --git a/index.js b/index.js index f4543f7..286a5f8 100644 --- a/index.js +++ b/index.js @@ -30,9 +30,11 @@ module.exports = { query.options = options; activeQueries.push(query); - query.on('finished', function() { + query.on('finished',function(state) { var i = activeQueries.indexOf(query); if(i >= 0) activeQueries.splice(i, 1); + + if(options.callback) options.callback(state); }); process.nextTick(function() {