Commit f52fa9c8 authored by antirek's avatar antirek

promisify context.exec

parent dc1f649a
......@@ -95,16 +95,6 @@ Context.prototype.end = function () {
return Q.resolve();
};
Context.prototype.exec = function() {
var args = Array.prototype.slice.call(arguments, 0);
var last = args.pop();
if(typeof last !== 'function') {
args.push(last);
last = function () { }
}
this.send('EXEC ' + args.join(' ') + '\n', last);
};
Context.prototype.sendCommand = function (command) {
var defer = new Q.defer();
this.send(command + '\n', function (err, result){
......@@ -123,10 +113,15 @@ Context.prototype.onEvent = function (event) {
defer.resolve(data);
});
return defer.promise;
}
};
Context.prototype.exec = function() {
var args = Array.prototype.slice.call(arguments, 0);
return this.sendCommand('EXEC ' + args.join(' '));
};
Context.prototype.dial = function (num, timeout, params, cb) {
this.exec('Dial', num + ',' + timeout + ',' + params, cb);
Context.prototype.dial = function (num, timeout, params) {
return this.exec('Dial', num + ',' + timeout + ',' + params);
};
Context.prototype.databaseDel = function (family, key) {
......
......@@ -96,9 +96,10 @@ describe('Context', function() {
context.stream.write('\n');
});
context.exec('test', 'boom', function(err, res) {
done(err);
context.exec('test', 'boom').then(function(){
done();
});
});
});
......@@ -111,10 +112,12 @@ describe('Context', function() {
context.stream.write('200 result=0\n');
});
context.exec('test', function(err, res) {
context.exec('test')
.then(function (res) {
expect(res.result).to.eql('0');
context.exec('test 2', function(err, res) {
return context.exec('test 2');
})
.then(function (res) {
expect(res.result).to.eql('1');
done();
});
......@@ -122,7 +125,7 @@ describe('Context', function() {
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