I am considering using the https://github.com/chuntaro/emacs-promise/ package to improve lsp-mode readability. There are multiple recurring patterns which can be generalized using promise and in addition to that, we will reduce the callback hell in lsp-mode and even more in dap-mode which has much more complex initialization phase.
E. g.
(promise-chain (lsp--delay :seconds 1
:cancel-token :foo)
(then (lambda (_)
(lsp-promise-request <lsp-method-params>)))
(then (lambda (lsp-method-result)
;; handle result
)))
Also, some of the code directly maps to promise calls - e. g. when we call multiple servers and then merge the results.
We could have even anamorphic versions which directly bind result variable
(promise-chain (lsp--delay :seconds 1
:cancel-token :foo)
(thena (lsp-promise-request <lsp-method-params>)))
(thena ;; use result
)))
I've extensively using https://github.com/kiwanami/emacs-deferred, which seems to has much more API and seems to be more stable.
It also can easily to convert from a callback expected function to deferred function with simple macro
(defmacro lsp--deferrize (orig-func &rest args)
"Change ORIG-FUNC (&rest ARGS CALLBACK) to deferred form."
(let* ((d (deferred:new #'identity))
(args (nconc args `((lambda (res)
(deferred:callback-post ,d res))))))
`(progn
(funcall ,orig-func ,@args)
,d)))
Also if we're full async/await pattern to simplify the implementation, https://github.com/skeeto/emacs-aio is also a good candidate. The only drawback is it requires Emacs 26.1 (although I doubt it can work with just Emacs 25).
deferred.el looks good too - AFAICS it covers the same use case. aio uses generators so it is not an option unless we decide to drop 25.1 .
emacs 27 should be out soon, so it should be a good time to drop emacs 25 support :)
On March 3, 2020 12:30:18 PM GMT+03:00, Ivan Yonchovski notifications@github.com wrote:
deferred.el looks good too - AFAICS it covers the same use case. aio
uses generators so it is not an option unless we decide to drop 25.1 .--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/emacs-lsp/lsp-mode/issues/1471#issuecomment-593852670
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
I spent some time checking both emacs-promise and deferred - IMO both will work and both are less than 1000 LOC which makes them simple enough so we can fix/support them if we need something.
aio looks interesting, it seems like it is a bigger commitment, I will have to spent more time testing it.
I've extensively using https://github.com/kiwanami/emacs-deferred, which seems to has much more API and seems to be more stable.
But seems to be unsupported - https://github.com/kiwanami/emacs-deferred/issues/56 ?
But seems to be unsupported - kiwanami/emacs-deferred#56 ?
Ooops, with the deprecation of emacs 25, can we consider switch to aio? Which has async and await syntax, which is easier to use, especially for other who come to elisp from other language.
Ooops, with the deprecation of emacs 25, can we consider switch to
aio?
IMO promise/deferred are a better fit because we often have tasks that directly match to promise/deferred primitives e. g.
But I might be wrong and those patterns might be supported by aio as well.
But seems to be unsupported -
https://github.com/kiwanami/emacs-deferred/issues/56 ?
At the same time I had better luck with https://github.com/chuntaro/emacs-promise/issues/37