Skip to content

Commit

Permalink
feat: Add elin.interceptor.connect/output-channel-interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Jan 18, 2024
1 parent 6398995 commit 17798ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/elin/handler/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
0 [nil nil]
1 [nil (first params)]
params)
result (-> {:cwd cwd :host host :port port}
result (-> {:message msg :cwd cwd :host host :port port}
(e.u.interceptor/execute
[e.i.connect/port-auto-detecting-interceptor]
[e.i.connect/port-auto-detecting-interceptor
e.i.connect/output-channel-interceptor]
(fn [{:as ctx :keys [host port]}]
(if (and host port)
(let [client (e.p.nrepl/add-client! client-manager host port)]
Expand Down
15 changes: 15 additions & 0 deletions src/elin/interceptor/connect.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(ns elin.interceptor.connect
(:require
[clojure.core.async :as async]
[elin.protocol.rpc :as e.p.rpc]
[elin.util.file :as e.u.file]))

(def port-auto-detecting-interceptor
Expand All @@ -13,3 +15,16 @@
(slurp)
(Long/parseLong))]
(assoc ctx :host host' :port port'))))})

(def output-channel-interceptor
{:name ::output-channel-interceptor
:leave (fn [{:as ctx :keys [message client]}]
(when client
(async/go-loop []
(let [ch (get-in client [:connection :output-channel])
{:keys [text]} (async/<! ch)]
(when text
;; TODO FIXME
(e.p.rpc/echo-message message (str "OUTPUT: " text) "ErrorMsg")
(recur)))))
ctx)})

0 comments on commit 17798ad

Please sign in to comment.