pandora
Version:
A powerful and lightweight application manager for Node.js applications powered by TypeScript.
66 lines • 2.54 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const ServiceReconciler_1 = require("../service/ServiceReconciler");
const pandora_env_1 = require("pandora-env");
const WorkerContextAccessor_1 = require("./WorkerContextAccessor");
/**
* Class WorkerContext
* 1. Inject the service
* 2. manage the process's lifecycle, provide start() and stop()
* 3. drive the lifecycle of the service
*/
class WorkerContext {
constructor(processRepresentation) {
this.processRepresentation = processRepresentation;
this.serviceReconciler = new ServiceReconciler_1.ServiceReconciler(processRepresentation, this);
this.workerContextAccessor = new WorkerContextAccessor_1.WorkerContextAccessor(this);
}
/**
* Get environment object
* @returns {Environment}
*/
getEnvironment() {
return pandora_env_1.EnvironmentUtil.getInstance().getCurrentEnvironment();
}
/**
* Bind services
* @param {ServiceRepresentation | ServiceRepresentation[]} services
*/
bindService(services) {
if (Array.isArray(services)) {
for (const service of services) {
this.serviceReconciler.receiveServiceRepresentation(service);
}
return;
}
this.serviceReconciler.receiveServiceRepresentation(services);
}
/**
* Start worker, drive the lifecycle of the service
* @returns {Promise<void>}
*/
start() {
return __awaiter(this, void 0, void 0, function* () {
yield this.serviceReconciler.start();
});
}
/**
* Stop worker, drive the lifecycle of the service
* @returns {Promise<void>}
*/
stop() {
return __awaiter(this, void 0, void 0, function* () {
yield this.serviceReconciler.stop();
});
}
}
exports.WorkerContext = WorkerContext;
//# sourceMappingURL=WorkerContext.js.map