Commit 4c368700 authored by Sergey Razuvaev's avatar Sergey Razuvaev

use native Promise

parent dddca25e
node_modules/
coverage
html-report
\ No newline at end of file
html-report
package-lock.json
var Readable = require('readable-stream');
var EventEmitter = require('events').EventEmitter;
var state = require('./state');
var Q = require('q');
var commands = require('./command');
//base context
......@@ -110,30 +109,33 @@ Context.prototype.send = function (msg, cb) {
Context.prototype.end = function () {
this.stream.end();
return Q.resolve();
return Promise.resolve();
};
Context.prototype.sendCommand = function (command) {
var defer = new Q.defer();
if (this.debug) console.log('command', command);
var self = this;
this.send(command + '\n', function (err, result) {
if (self.debug) console.log('err:', err, 'result:', result);
if (err) {
defer.reject(err);
} else {
defer.resolve(result);
}
});
return defer.promise;
return new Promise(function (resolve, reject) {
self.send(command + '\n', function (err, result) {
if (self.debug) console.log('err:', err, 'result:', result);
if (err) {
reject(err);
} else {
resolve(result);
}
});
})
};
Context.prototype.onEvent = function (event) {
var defer = new Q.defer();
this.on(event, function (data) {
defer.resolve(data);
});
return defer.promise;
var self = this
return new Promise(function (resolve) {
self.on(event, function (data) {
resolve(data);
})
})
};
//additional agi commands
......
......@@ -15,7 +15,6 @@
"node": ">=0.8.0"
},
"dependencies": {
"q": "^1.4.1",
"readable-stream": "*"
},
"devDependencies": {
......
......@@ -135,17 +135,15 @@ describe('Context', function() {
context.exec('test')
.then(function (res) {
expect(res.result).to.eql('0');
process.nextTick(function() {
context.stream.write('200 result=1\n');
});
return context.exec('test 2');
})
.then(function (res) {
expect(res.result).to.eql('1');
done();
});
process.nextTick(function() {
context.stream.write('200 result=1\n');
});
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment