Fork me on GitHub
#nrepl
<
2019-08-17
>
cfleming00:08:30

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?

cfleming00:08:50

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.

cfleming00:08:19

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.

cfleming00:08:32

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.

cfleming00:08:26

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

dominicm04:08:04

Cider provides middleware for this I think.

bozhidar06:08:24

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

bozhidar06:08:03

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

bozhidar06:08:24

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

bozhidar06:08:53

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

bozhidar06:08:14

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

bozhidar07:08:35

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

bozhidar07:08:46

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

bozhidar07:08:23

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.

dominicm08:08:51

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

pez08:08:00

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

bozhidar09:08:39

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

pez09:08:58

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