Skip to content

Commit 5102acf

Browse files
committed
Use try plus finally for the cp command
This makes it much more explicit that the channel needs to be closed when the rest of the code is done executing. In reality this is still just a proof of concept on how to use the internal socket repl to get a result back to the plugin, but better a good example. ;-)
1 parent 04f950d commit 5102acf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/socket_repl/socket_repl_plugin.clj

+8-8
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,18 @@
219219
plugin
220220
(fn [msg]
221221
(let [code-form "(map #(.getAbsolutePath %) (clojure.java.classpath/classpath))"]
222-
(log/info msg)
223222
(async/>!! (socket-repl/input-channel internal-socket-repl)
224223
code-form)
225-
(log/info "I'm in!")
226224
(async/thread
227225
(let [res-chan (async/chan 1 (filter #(= (:form %) code-form)))]
228-
(socket-repl/subscribe-output internal-socket-repl res-chan)
229-
(let [res (async/<!! res-chan)]
230-
(log/info (:ns res))
231-
(log/info (:ms res))
232-
(log/info (:val res))
233-
(.close res-chan))))))))
226+
(try
227+
(socket-repl/subscribe-output internal-socket-repl res-chan)
228+
(let [res (async/<!! res-chan)]
229+
(log/info (:ns res))
230+
(log/info (:ms res))
231+
(log/info (:val res)))
232+
(finally
233+
(.close res-chan)))))))))
234234

235235
(nvim/register-method!
236236
nvim

0 commit comments

Comments
 (0)