node-web-mvc
Version:
node spring mvc
70 lines (69 loc) • 2.14 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const net_1 = require("net");
const WorkerInvoker_1 = __importDefault(require("./WorkerInvoker"));
class WorkerSocket extends net_1.Socket {
address() {
return this.myAddress || {};
}
constructor(port, type, address) {
super();
this.invoker = new WorkerInvoker_1.default(port);
this.type = type;
this.myAddress = address;
}
invoke(name, args) {
return this.invoker.invoke(this.type, name, args);
}
write(str, encoding, cb) {
const newEncoding = typeof encoding == 'string' ? encoding : undefined;
const callback = typeof encoding == 'function' ? encoding : cb;
this.invoker.invoke('response', 'write', [str, newEncoding]).then(() => callback === null || callback === void 0 ? void 0 : callback(), callback);
return true;
}
end(chunk, arg1, cb) {
let callback;
let encoding;
let buffer;
switch (arguments.length) {
case 1:
callback = cb;
break;
case 2:
buffer = chunk;
callback = cb;
break;
case 3:
buffer = chunk;
encoding = arg1;
callback = cb;
break;
}
this.invoker.invoke('response', 'end', [buffer, encoding]).finally(callback);
return this;
}
setKeepAlive(enable, initialDelay) {
this.invoke('setKeepAlive', [enable, initialDelay]);
return this;
}
setNoDelay(noDelay) {
this.invoke('setNoDelay', [noDelay]);
return this;
}
setEncoding(encoding) {
this.invoke('setEncoding', [encoding]);
return this;
}
pause() {
this.invoke('pause', []);
return this;
}
resume() {
this.invoke('resume', []);
return this;
}
}
exports.default = WorkerSocket;