2017-08-09 00:03:57 +02:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const log = require("./log");
|
|
|
|
const events = require("events");
|
2017-08-23 15:52:37 +02:00
|
|
|
class LastChainItem {
|
|
|
|
begin() {
|
|
|
|
}
|
|
|
|
send(message) {
|
|
|
|
log.info(`Last chain item, final result ${message}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let lastChainItem = new LastChainItem();
|
2017-08-09 00:03:57 +02:00
|
|
|
class AChainItem extends events.EventEmitter {
|
|
|
|
constructor(label) {
|
|
|
|
super();
|
|
|
|
this._label = label;
|
2017-08-23 15:52:37 +02:00
|
|
|
this._next = lastChainItem;
|
2017-08-09 00:03:57 +02:00
|
|
|
}
|
|
|
|
toString() {
|
2017-08-23 15:52:37 +02:00
|
|
|
return `<${this._label}>`;
|
2017-08-09 00:03:57 +02:00
|
|
|
}
|
|
|
|
registerNext(next) {
|
|
|
|
this._next = next;
|
|
|
|
}
|
|
|
|
send(message) {
|
|
|
|
this.emit('yourturn', message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.AChainItem = AChainItem;
|
2017-08-23 15:52:37 +02:00
|
|
|
class ABaseChainItem extends AChainItem {
|
2017-08-09 00:03:57 +02:00
|
|
|
constructor(label) {
|
|
|
|
super(label);
|
|
|
|
}
|
|
|
|
begin() {
|
|
|
|
if (this._next != null) {
|
|
|
|
this._next.begin();
|
|
|
|
}
|
|
|
|
this.addListener('yourturn', (message) => {
|
|
|
|
log.info(`Calling ${this.toString()}`);
|
2017-08-23 15:52:37 +02:00
|
|
|
let result = this.func(message);
|
|
|
|
this._next.send(result);
|
2017-08-09 00:03:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-08-23 15:52:37 +02:00
|
|
|
exports.ABaseChainItem = ABaseChainItem;
|
|
|
|
class ChainItem extends ABaseChainItem {
|
|
|
|
toString() {
|
|
|
|
let funcName = (this._chainItemFunc.name === "") ? "lambda" : this._chainItemFunc.name;
|
|
|
|
return `<${funcName}, ${this._label}>`;
|
|
|
|
}
|
|
|
|
registerFunc(func) {
|
|
|
|
this._chainItemFunc = func;
|
|
|
|
}
|
|
|
|
func(message) {
|
|
|
|
return this._chainItemFunc(message);
|
|
|
|
}
|
|
|
|
}
|
2017-08-09 00:03:57 +02:00
|
|
|
exports.ChainItem = ChainItem;
|
|
|
|
//# sourceMappingURL=callchain.js.map
|