UNPKG

@botol/tg-threads

Version:

## Options | Name | Type | Default | Description | |---|---|---|---| | scriptPath | string | - | Path to script | | workerCount | number | 3 | (Optional) Workers count | | execTimeout | number | 0 | (Optional) Max allowed time to process update (Set 0 to

30 lines (29 loc) 927 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BotThreads = void 0; const tg_dipo_1 = require("@botol/tg-dipo"); const worker_threads_1 = require("worker_threads"); const wpoll_1 = require("wpoll"); function BotThreads(bot, options) { let wpoll; if (worker_threads_1.isMainThread) { wpoll = new wpoll_1.WPoll(options.scriptPath, { WPollNodeCount: options.workerCount, execTimeout: options.execTimeout, recreateOnTimeout: true, }); wpoll.init(); } else { new wpoll_1.WWorker((update) => { return bot.handle(new tg_dipo_1.ContextTG(update, bot['client'])); }); } return (ctx, next) => { if (worker_threads_1.isMainThread) { return wpoll.exec(ctx.update); } return next(); }; } exports.BotThreads = BotThreads;