Sorry if this is due to a misunderstanding of how callbacks work, but I'm new to Node and really need to return useful error messages, but at the moment return a success followed later by the error which is caught:
connectDevice: function (ip) {
var port = 5555;
console.log("Connecting to device " + ip + ":5555")
client.connect(ip, port)
.then(function() {
return false; // wait until no errors confirmed
})
.catch(function(err) {
if (err === null) {
return false;
} else {
if (debug) console.error('Could not connect to device at IP ' + ip, err.stack);
console.log('Could not connect to device');
return true; // return error = true
}
});
},
I'm trying to connect to an android device using adbkit which uses promises, however I can't figure out how to adapt them from examples as there's no parent function.
It's important it waits to confirm a connecion before sending commands however. I get this is because of Node's event driven nature but don't know enough how to properly deal with this situation.
Thanks for any help and patience.