Skip to content

Instantly share code, notes, and snippets.

@fortruce
Created April 22, 2015 20:12
Show Gist options
  • Save fortruce/c1523b113314b132225e to your computer and use it in GitHub Desktop.
Save fortruce/c1523b113314b132225e to your computer and use it in GitHub Desktop.
BluebirdMikrotik.prototype.connect = function () {
var p = new Promise.defer();
//console.log('intentando conexion')
this.api.connect(function(c) {
console.log(c)
this.con=c
console.log('.')
console.log(this.con)
p.resolve()
}.bind(this)); //*********************** BIND
this.api.on('error',function (e) {
//console.log(e)
p.reject(e)
})
return p.promise
}
BluebirdMikrotik.prototype.send = function(data){
data = data || 'data\n'
var p = new Promise.defer();
console.log(this.con)
var chan=this.con.openChannel();
chan.write(data,function() {
chan.on('trap',function(data) {
// console.log('t');
p.reject(data)
});
chan.on('done',function(data) {
var parsed = Api.parseItems(data);
console.log(parsed)
chan.close();
this.con.close();
p.resolve(parsed)
}.bind(this)); //*********************** BIND
}.bind(this)); //*********************** BIND
return p.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment