|
24 | 24 | import java.io.PrintWriter; |
25 | 25 | import java.nio.charset.Charset; |
26 | 26 | import java.util.concurrent.Callable; |
27 | | -import java.util.concurrent.ExecutorService; |
28 | | -import java.util.concurrent.Executors; |
29 | | -import java.util.concurrent.Future; |
| 27 | +import java.util.concurrent.CompletableFuture; |
30 | 28 | import java.util.function.Consumer; |
31 | 29 | import java.util.function.IntConsumer; |
32 | 30 | import java.util.function.IntSupplier; |
|
46 | 44 |
|
47 | 45 | public class FastTerminal implements TerminalExt { |
48 | 46 |
|
49 | | - final Future<Terminal> terminal; |
| 47 | + private final CompletableFuture<Terminal> terminal; |
50 | 48 |
|
51 | 49 | public FastTerminal(Callable<Terminal> builder, Consumer<Terminal> consumer) { |
52 | | - ExecutorService executor = Executors.newSingleThreadExecutor(); |
53 | | - terminal = executor.submit(() -> { |
54 | | - try { |
55 | | - Terminal terminal = builder.call(); |
56 | | - consumer.accept(terminal); |
57 | | - return terminal; |
58 | | - } catch (Exception e) { |
59 | | - throw new MavenException(e); |
60 | | - } finally { |
61 | | - executor.shutdown(); |
62 | | - } |
63 | | - }); |
| 50 | + this.terminal = new CompletableFuture<>(); |
| 51 | + new Thread( |
| 52 | + () -> { |
| 53 | + try { |
| 54 | + Terminal term = builder.call(); |
| 55 | + consumer.accept(term); |
| 56 | + terminal.complete(term); |
| 57 | + } catch (Exception e) { |
| 58 | + terminal.completeExceptionally(new MavenException(e)); |
| 59 | + } |
| 60 | + }, |
| 61 | + "fast-terminal-thread") |
| 62 | + .start(); |
64 | 63 | } |
65 | 64 |
|
66 | 65 | public TerminalExt getTerminal() { |
|
0 commit comments