nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
cfleming 2019-08-17T00:50:30.002400Z

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?

cfleming 2019-08-17T00:51:50.003700Z

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 2019-08-17T00:53:19.005400Z

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.

cfleming 2019-08-17T00:54:32.006500Z

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.

cfleming 2019-08-17T00:55:26.007600Z

This is also an issue with Clojure if an eval spins up a new thread.

dominicm 2019-08-17T04:51:04.008800Z

Cider provides middleware for this I think.

bozhidar 2019-08-17T06:45:24.009Z

> 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.

bozhidar 2019-08-17T06:50:03.011200Z

@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.

bozhidar 2019-08-17T06:50:24.011500Z

> Keep the latest 100 around and expire them in a LRU fashion?

bozhidar 2019-08-17T06:50:53.012Z

I’d probably go with this one, although I doubt you’ll need more than the last 10.

bozhidar 2019-08-17T06:54:14.014300Z

> 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.

bozhidar 2019-08-17T07:50:35.014500Z

> 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?

bozhidar 2019-08-17T07:50:46.014800Z

Can you elaborate on this? Some example would be useful.

bozhidar 2019-08-17T07:51:23.015600Z

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.

dominicm 2019-08-17T08:54:51.016200Z

Maybe I misunderstood, I thought he was after wrap-out

pez 2019-08-17T08:58:00.017300Z

What is wrap-out? Sounds like something I've been out looking for...

bozhidar 2019-08-17T09:13:53.017600Z

@pez Output redirection middleware https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/out.clj

bozhidar 2019-08-17T09:14:39.018400Z

It ensure that output doesn’t end up in the server terminal instead of the user’s REPL/code buffer.

pez 2019-08-17T09:15:58.019Z

> 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! 😄