Skip to content

Commit 4540024

Browse files
committed
Add sensible buffers to i/o channels
1 parent 83056b9 commit 4540024

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/neovim_client/rpc.clj

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
(defn create-input-channel
2222
"Read messages from the input stream, put them on a channel."
2323
[input-stream]
24-
(let [chan (async/chan)
24+
(let [chan (async/chan 1024)
2525
input-stream (DataInputStream. input-stream)]
26-
(async/go
27-
(while true
28-
(log/info "waiting for input stream")
29-
(let [msg (msgpack/unpack-stream input-stream)]
30-
(log/info "stream -> msg -> in chan: " msg)
31-
(async/>! chan msg))))
26+
(async/go-loop []
27+
(let [msg (msgpack/unpack-stream input-stream)]
28+
(log/info "stream -> msg -> in chan: " msg)
29+
(async/>! chan msg))
30+
(recur))
3231
chan))
3332

3433
(defn write-msg!
@@ -40,13 +39,13 @@
4039
(defn create-output-channel
4140
"Make a channel to read messages from, write to output stream."
4241
[output-stream]
43-
(let [chan (async/chan)
42+
(let [chan (async/chan 1024)
4443
output-stream (DataOutputStream. output-stream)]
45-
(async/go
46-
(while true
47-
(let [msg (async/<! chan)]
48-
(log/info "stream <- msg <- out chan: " msg)
49-
(write-msg! (msgpack/pack msg) output-stream))))
44+
(async/go-loop []
45+
(let [msg (async/<! chan)]
46+
(log/info "stream <- msg <- out chan: " msg)
47+
(write-msg! (msgpack/pack msg) output-stream))
48+
(recur))
5049
chan))
5150

5251
(declare send-message-async!)
@@ -57,21 +56,21 @@
5756
(reset! out-chan (create-output-channel output-stream))
5857

5958
;; Handle stuff on the input channel -- where should this live?
60-
(async/go
61-
(while true
62-
;; TODO - let the in-chan, if we leave this code here.
63-
(let [msg (async/<! @in-chan)]
64-
(condp = (msg-type msg)
59+
(async/go-loop []
60+
;; TODO - let the in-chan, if we leave this code here.
61+
(let [msg (async/<! @in-chan)]
62+
(condp = (msg-type msg)
6563

66-
msg/+response+
67-
(let [f (:fn (get @msg-table (id msg)))]
68-
(swap! msg-table dissoc (id msg))
69-
(f (value msg)))
64+
msg/+response+
65+
(let [f (:fn (get @msg-table (id msg)))]
66+
(swap! msg-table dissoc (id msg))
67+
(f (value msg)))
7068

71-
msg/+request+
72-
(let [f (get @method-table (method msg) method-not-found)
73-
result (f msg)]
74-
(send-message-async! (->response-msg (id msg) result) nil)))))))
69+
msg/+request+
70+
(let [f (get @method-table (method msg) method-not-found)
71+
result (f msg)]
72+
(send-message-async! (->response-msg (id msg) result) nil))))
73+
(recur)))
7574

7675
;; ***** Public *****
7776

0 commit comments

Comments
 (0)