Add slash command for dice rolls. Create class for worker wrappers

This commit is contained in:
SillyLossy
2023-05-31 13:57:08 +03:00
parent b2016fa7f3
commit ef90c31643
7 changed files with 836 additions and 885 deletions

View File

@ -1,5 +1,5 @@
import { callPopup, getRequestHeaders, saveSettingsDebounced } from "../../../script.js";
import { getContext, getApiUrl, modules, extension_settings } from "../../extensions.js";
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper } from "../../extensions.js";
export { MODULE_NAME };
const MODULE_NAME = 'expressions';
@ -58,24 +58,6 @@ function onExpressionsShowDefaultInput() {
}
}
let isWorkerBusy = false;
async function moduleWorkerWrapper() {
// Don't touch me I'm busy...
if (isWorkerBusy) {
return;
}
// I'm free. Let's update!
try {
isWorkerBusy = true;
await moduleWorker();
}
finally {
isWorkerBusy = false;
}
}
async function moduleWorker() {
const context = getContext();
@ -509,6 +491,7 @@ async function onClickExpressionDelete(event) {
addExpressionImage();
addSettings();
setInterval(moduleWorkerWrapper, UPDATE_INTERVAL);
moduleWorkerWrapper();
const wrapper = new ModuleWorkerWrapper(moduleWorker);
setInterval(wrapper.update.bind(wrapper), UPDATE_INTERVAL);
moduleWorker();
})();