Skip to content

Commit

Permalink
Update promise in returnSingleBotFromCache
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchangelWTF committed Jan 12, 2025
1 parent 5a0c6d6 commit c3c266d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions project/src/controllers/BotController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,18 @@ export class BotController {

// Check cache for bot using above key
if (!this.botGenerationCacheService.cacheHasBotWithKey(cacheKey)) {
const botPromises: Promise<void>[] = [];
// No bot in cache, generate new and return one
for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) {
botPromises.push(this.generateSingleBotAndStoreInCache(botGenerationDetails, sessionId, cacheKey));
}
// No bot in cache, generate new and store in cache
await Promise.all(
Array.from({ length: botGenerationDetails.botCountToGenerate }).map(
async () => await this.generateSingleBotAndStoreInCache(botGenerationDetails, sessionId, cacheKey),
),
);

await Promise.all(botPromises).then(() => {
this.logger.debug(
`Generated ${botGenerationDetails.botCountToGenerate} ${botGenerationDetails.role} (${
botGenerationDetails.eventRole ?? ""
}) ${botGenerationDetails.botDifficulty} bots`,
);
});
this.logger.debug(
`Generated ${botGenerationDetails.botCountToGenerate} ${botGenerationDetails.role} (${
botGenerationDetails.eventRole ?? ""
}) ${botGenerationDetails.botDifficulty} bots`,
);
}

const desiredBot = this.botGenerationCacheService.getBot(cacheKey);
Expand Down

0 comments on commit c3c266d

Please sign in to comment.