Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/api/v1/chat/completions/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let initPromise = null;
*/
function ensureInitialized() {
if (!initPromise) {
initPromise = initTranslators().then(() => {
initPromise = Promise.resolve(initTranslators()).then(() => {
console.log("[SSE] Translators initialized");
});
Comment on lines +12 to 14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While Promise.resolve() correctly fixes the TypeError, using an async IIFE (Immediately Invoked Function Expression) would make the logic slightly more robust, especially regarding error handling. If initTranslators() were to throw an error, this approach would cache the resulting rejected promise, preventing repeated failing attempts on subsequent calls. This improves predictability and aligns well with the singleton pattern you're using for initialization.

    initPromise = (async () => {
      await initTranslators();
      console.log("[SSE] Translators initialized");
    })();

}
Expand Down