Fork me on GitHub
#vim
<
2022-11-17
>
mars0i23:11:31

I'm trying to understand sessions in Conjure. When I start nvim with Conjure, I have two sessions. If I list the sessions, I see that I'm in one, and I can use <localleader>ss (for example) to switch to the other one. I can also use <localleader>sf to create additional sessions, and then I can switch between them.

mars0i23:11:50

First question: Why does conjure I start with two sessions? I thought that maybe one was for a connection to another nrepl instance, but I seem to be able to eval in either session. Should that be so for the nrepl connection session? Not sure. Second question: If I have a long-running process, I can run it in one session. Then anything I evaluate waits until the long-running process ends. But if I switch to another session, I can get immediate evaluation. That makes sense. But now consider two sessions, neither of which has a long-running process. I can run (def foo 42) in one, then switch to the other session, and I find that foo is defined there as well. So a namespace is shared across all sessions, but they can run in parallel? Maybe that is what's happening and maybe that makes sense, but I am not sure. Thanks for any clarifying remarks you can give me. Or send me to some docs, blog post, etc. that I'm unaware of. Thanks!

Dumch05:11:05

There is also a #CK143P6D7 channel

🙏 1
Leaf Garland03:11:16

Usually if you see 2 sessions at startup it is because whichever program you are running to launch the nrepl server also has a repl prompt. So one session will be for that repl prompt, and one for the session created when conjure connected. If you started nrepl in headless mode then you should only see 1 session, once conjure has connected. As you have seen clojure namespaces and the vars within them are global, hence shared between sessions. Each nrepl session executes on its own thread and has its own repl vars like *1, *e, etc. Some more info here https://metaredux.com/posts/2019/12/20/userstanding-nrepl-sessions.html.

🙏 1
mars0i18:11:35

Thanks @U02EP7NKPAL. Thanks @UL05W6AEM --I didn't know about the #CK143P6D7 channel.

mars0i18:11:38

I guess my question is whether there is any reason to avoid using both of the first two sessions to evaluate long-running code. It seems to work. I just wonder if I will gum up communication between the client and server if I do that. I see no sign of a problem, though.

Leaf Garland19:11:40

Nrepl has ephemeral sessions which I think conjure or other editors would use for any tooling specific communications. I think you can assume you own the sessions you see listed.

mars0i23:11:54

OK, great--thanks @U02EP7NKPAL.

Olical10:11:52

Conjure actually reuses the sessions in the list and tries to connect to an existing one rather than opening a new one on every connection. If this is an anti pattern I'm happy to change it.

Olical10:11:21

And it's okay to have most things on one session, they have message ids so they don't get in each others way. They will block execution sometimes I think since a session = a thread... pretty sure. So I mostly only use sessions for multiple long running threads that block nREPL OR for a CLJS session etc that's hijacking the eval in some way.

mars0i04:11:11

Thanks @U38J3881W! I definitely get blocking when I execute some Clojure code in the selected session while I'm waiting for previously executed code to finish. The main point that I think I understand now is that I can use both of the original sessions, and more if I add sessions. I just need one session that is not dedicated to a long-running process in order to get an immediate response from nrepl. (I love conjure, by the way. I used vim-iced for a while, and it was nice, but Conjure provides a much smoother experience for me. It's the reason that I use nvim with Clojure; I actually prefer MacVim's gvim for other sorts of work, but nvim with conjure is great for Clojure.)