lsp4j
lsp4j copied to clipboard
change Launcher startListening result to CompletableFuture?
Hi Lsp4J,
I wonder if it would make sense to have a CompletableFuture
as the result type of the JSON-RPC Launcher#startListening?
The Future is create here:
org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.startProcessing(MessageProducer, MessageConsumer, ExecutorService)
org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.beginProcessing(ExecutorService)
Could it be changed to CompletableFuture.runAsync( reader/this, executorService )
In the ChatExample from here: https://www.eclipse.org/community/eclipse_newsletter/2017/may/article2.php The class SocketLauncher is mainly there to do the conversion Future -> CompletableFuture and creates a blocking thread to do so. This seems waste to me.
Frank
Hi Frank,
Thank you for your suggestion, it sounds interesting.
Until someone with a deeper knowledge of the subject replies, here are my two cents:
-
Obviously, this would be a breaking API change. In particular, it could break any existing implementation of the
Launcher
interface. -
There is a difference in behavior of the
cancel
method of aFuture
returned fromExecutorService.submit
and aCompletableFuture
returned fromCompletableFuture.runAsyc
. The latter ignores themayInterruptIfRunning
parameter, i.e. it will not try to stop the running task.