mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
Change to callback method
This commit is contained in:
parent
8552d0674f
commit
fd735e248f
2 changed files with 7 additions and 2 deletions
|
@ -9,7 +9,7 @@ var Gamedig = require('gamedig');
|
||||||
Gamedig.query({
|
Gamedig.query({
|
||||||
type: 'minecraft',
|
type: 'minecraft',
|
||||||
host: 'mc.example.com',
|
host: 'mc.example.com',
|
||||||
success: function(state) {
|
callback: function(state) {
|
||||||
if(state.error) console.log("Server is offline");
|
if(state.error) console.log("Server is offline");
|
||||||
else console.log(state);
|
else console.log(state);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@ Gamedig.query({
|
||||||
|
|
||||||
State Object
|
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
|
The returned state object may contain some or all of the following keys, depending on
|
||||||
what is available from the queried server:
|
what is available from the queried server:
|
||||||
|
|
||||||
|
|
4
index.js
4
index.js
|
@ -30,9 +30,11 @@ module.exports = {
|
||||||
query.options = options;
|
query.options = options;
|
||||||
activeQueries.push(query);
|
activeQueries.push(query);
|
||||||
|
|
||||||
query.on('finished', function() {
|
query.on('finished',function(state) {
|
||||||
var i = activeQueries.indexOf(query);
|
var i = activeQueries.indexOf(query);
|
||||||
if(i >= 0) activeQueries.splice(i, 1);
|
if(i >= 0) activeQueries.splice(i, 1);
|
||||||
|
|
||||||
|
if(options.callback) options.callback(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
|
|
Loading…
Reference in a new issue