I’d like to be able to send arbitrary messages back from my nREPL server process to the client. Any suggestions for how to handle this?
Currently the way this works in Cursive is that for a particular evaluation, I register a handler which handles values, out & err, errors etc, and associate the handler with the eval ID. When the eval is done I remove the handler so they don’t hang around forever.
However this doesn’t work very well for some use cases. For example, when working with CLJS when an eval results in a promise it would be nice to be able to send that value back to the client when the promise is fulfilled, but by that time the original evaluation is probably done and the handler will have been cleaned up.
I don’t want to keep all handlers around forever, but I’m not sure what a good expiry policy would be for them. Keep them around for n seconds? Keep the latest 100 around and expire them in a LRU fashion? I’m not sure.
This is also an issue with Clojure if an eval spins up a new thread.
Cider provides middleware for this I think.
> Currently the way this works in Cursive is that for a particular evaluation, I register a handler which handles values, out & err, errors etc, and associate the handler with the eval ID. When the eval is done I remove the handler so they don’t hang around forever.
@cfleming CIDER operates similarly. I just remove the handlers when a message is :done
and fallback to a default handler for responses that come for messages without a removed handler. I’ve been meaning to improve this for ages, but I never got to doing so.
> Keep the latest 100 around and expire them in a LRU fashion?
I’d probably go with this one, although I doubt you’ll need more than the last 10.
> Cider provides middleware for this I think.
No, the handlers are purely a client concern. Every client decides themselves how to track responses and react to them - a handler in CIDER is just several lambdas that act on value
, err
, out
, etc for a particular message id.
> I’d like to be able to send arbitrary messages back from my nREPL server process to the client. Any suggestions for how to handle this?
Can you elaborate on this? Some example would be useful.
I assume you want to associate some extra data with the requests and it would be attached to the responses, but I’m not quite certain I got this right.
Maybe I misunderstood, I thought he was after wrap-out
What is wrap-out? Sounds like something I've been out looking for...
@pez Output redirection middleware https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/out.clj
It ensure that output doesn’t end up in the server terminal instead of the user’s REPL/code buffer.
> It ensure that output doesn’t end up in the server terminal instead of the user’s REPL/code buffer. So I was out looking for this! 😄