Open MTRNord opened 8 years ago
The functions return promises. If status
is also a promised function, do this:
status: function () {
return rcon.connect().then(() => {
return rcon.command('status').then(result => {
console.log('status check', result);
});
}).then(
() => rcon.disconnect()
).catch(err => {
console.log('caught', err);
console.log(err.stack);
});
},
If status
expects a callback, do this:
status: function (cb) {
return rcon.connect().then(() => {
return rcon.command('status').then(result => {
console.log('status check', result);
cb(null, result);
});
}).then(
() => rcon.disconnect()
).catch(err => {
console.log('caught', err);
console.log(err.stack);
cb(err);
});
},
Thanks that worked :)
OK it did not. If I call the function status I get Promise { <pending> }
and not the result :/
Try to call status
like this:
status().then(result => console.log('Got status', result))
Now the next "error" is Got status undefined
Can you send that promise based code?
HI I have following code in module.exports and want to get the awnser from the server returned by the function. How can I do that? I tried to put the return in front of the connect but that did gave me the state of the connection.