Introduce a state lock to prompt manager render function

This commit is contained in:
maver
2023-08-16 19:28:27 +02:00
parent 947289dffc
commit db5f815632

View File

@@ -183,6 +183,9 @@ function PromptManagerModule() {
} }
} }
// Either 0 for done or 1 for rendering
this.renderState = 0;
// Chatcompletion configuration object // Chatcompletion configuration object
this.serviceSettings = null; this.serviceSettings = null;
@@ -589,8 +592,10 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
*/ */
PromptManagerModule.prototype.render = function (afterTryGenerate = true) { PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
if (main_api !== 'openai' || if (main_api !== 'openai' ||
null === this.activeCharacter) return; null === this.activeCharacter ||
1 === this.renderState) return;
this.renderState = 1;
this.error = null; this.error = null;
const stopPropagation = (event) => { const stopPropagation = (event) => {
@@ -627,6 +632,7 @@ PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
this.log(error.stack); this.log(error.stack);
this.log('-----------------------------------------------------------'); this.log('-----------------------------------------------------------');
} finally { } finally {
this.renderState = 0;
configurationContainer.removeEventListener('click', stopPropagation, true); configurationContainer.removeEventListener('click', stopPropagation, true);
} }
} }