Skip to content

Commit

Permalink
Initialize Enso Terminal in a background thread (#11149)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Sep 24, 2024
1 parent a8810e1 commit c6d1857
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -959,12 +962,21 @@ private void runRepl(
}

private static MessageTransport replTransport() {
var repl = new Repl(makeTerminalForRepl());
ThreadFactory factory = (r) -> new Thread(r, "Initialize Enso Terminal");
var executor = Executors.newSingleThreadExecutor(factory);
var futureRepl = executor.submit(() -> new Repl(makeTerminalForRepl()));
MessageTransport transport =
(uri, peer) ->
DebugServerInfo.URI.equals(uri.toString())
? new DebuggerSessionManagerEndpoint(repl, peer)
: null;
(uri, peer) -> {
if (DebugServerInfo.URI.equals(uri.toString())) {
try {
var repl = futureRepl.get();
return new DebuggerSessionManagerEndpoint(repl, peer);
} catch (InterruptedException | ExecutionException ex) {
logger.error("Cannot initialize REPL transport", ex);
}
}
return null;
};
return transport;
}

Expand Down

0 comments on commit c6d1857

Please sign in to comment.