@lakutata/core
Version:
Lakutata Framework Core
34 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThreadManager = void 0;
const ThreadException_1 = require("../../exceptions/ThreadException");
const Thread_1 = require("../../lib/multipleRunner/lib/Thread");
class ThreadManager {
constructor() {
this.threadMap = new Map();
}
async createThread(threadConstructor) {
if (this.threadMap.has(threadConstructor))
return false;
const threadProxy = await (0, Thread_1.Thread)(threadConstructor);
this.threadMap.set(threadConstructor, threadProxy);
return true;
}
has(threadConstructor) {
return this.threadMap.has(threadConstructor);
}
get(threadConstructor) {
if (this.threadMap.has(threadConstructor)) {
return this.threadMap.get(threadConstructor);
}
throw new ThreadException_1.ThreadException(`Thread [${threadConstructor.name}] is not bound`);
}
async destroy(threadConstructor) {
if (this.threadMap.has(threadConstructor)) {
await this.threadMap.get(threadConstructor)?.terminate();
this.threadMap.delete(threadConstructor);
}
}
}
exports.ThreadManager = ThreadManager;
//# sourceMappingURL=ThreadManager.js.map