kitejs
Version:
the rpc framework Kite for Node.js
37 lines (36 loc) • 1.25 kB
JavaScript
;
exports.__esModule = true;
var thrift = require("thrift");
var Thrift = /** @class */ (function () {
function Thrift(addr, options) {
this.service = options['service'];
this.timeout = options['timeout'];
this.transport = options['transport'];
this.addr = addr;
}
Thrift.prototype.createConnection = function () {
var transport, protocol;
if (this.transport && this.transport === 'FRAMED') {
transport = thrift.TFramedTransport;
}
else {
transport = thrift.TBufferedTransport;
}
protocol = thrift.TBinaryProtocol;
return thrift.createConnection(this.addr.getHost(), this.addr.getPort(), {
transport: transport,
protocol: protocol,
'connect_timeout': this.timeout
});
};
Thrift.prototype.request = function (cb) {
if (!this.service) {
return cb(new Error('invalid service or not given, please use .loadService(<path>) given it.'));
}
var con = this.createConnection();
con.on('error', cb);
return cb(null, thrift.createClient(this.service, con), con);
};
return Thrift;
}());
exports.Thrift = Thrift;