Skip to content

Commit

Permalink
fix(translations): Do not block translating.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent 27d6f8f commit 2222c50
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/
package org.jitsi.jigasi.transcription;

import org.jitsi.jigasi.util.Util;

import java.util.*;
import java.util.concurrent.*;

/**
* This class manages the translations to be done by the transcriber.
Expand Down Expand Up @@ -45,6 +48,11 @@ public class TranslationManager
*/
private final TranslationService translationService;

/**
* The thread pool to serve all connect, disconnect ore reconnect operations.
*/
private static final ExecutorService threadPool = Util.createNewThreadPool("jigasi-translation");

/**
* Initializes the translationManager with a TranslationService
* and adds the default target language to the list.
Expand Down Expand Up @@ -171,20 +179,21 @@ private List<TranslationResult> getTranslations(
@Override
public void notify(TranscriptionResult result)
{
if (!result.isInterim())
threadPool.submit(() ->
{
List<TranslationResult> translations
= getTranslations(result);
Iterable<TranslationResultListener> translationResultListeners;

synchronized (listeners)
if (!result.isInterim())
{
translationResultListeners = new ArrayList<>(listeners);
}
List<TranslationResult> translations = getTranslations(result);
Iterable<TranslationResultListener> translationResultListeners;

translationResultListeners.forEach(
listener -> translations.forEach(listener::notify));
}
synchronized (listeners)
{
translationResultListeners = new ArrayList<>(listeners);
}

translationResultListeners.forEach(listener -> translations.forEach(listener::notify));
}
});
}

@Override
Expand Down

0 comments on commit 2222c50

Please sign in to comment.