Tim, Your middleware never sends a response. Each request message can produce multiple response messages, sent at some later time (i.e. the request/response cycle is fundamentally asynchronous). Handler return values are ignored.
So, assoc'ing the "result" into the request message as the return value of the handler function won't do anything. You need to construct a response message and send it on the transport hanging off of the request message; here's a concise real-world example from ritz: https://github.com/pallet/ritz/blob/develop/nrepl-middleware/src/ritz/nrepl/middleware/doc.clj And, be a mensch, and send a "done" status in the response, too, so message-scoped response seqs terminate properly without waiting for the read timeout to expire. :-) Cheers, - Chas On Dec 26, 2012, at 5:55 PM, Timothy Washington wrote: > Hi all, > > I'm trying to put together some nrepl middleware. To get a basic > understanding, I thought I would implement some simple nrepl middleware in a > test project as seen in A). I can execute `M-x nrepl-jack-in`. But executing > the client, gives me an empty result (`repl/response-values` pulls nil out of > ()). So I tried a bare bones communication example in the middleware page > (see B), but am still getting an error. > > I like the example given in the leiningen sample project. But it seems I need > to get the basics working in A) and B), first. > > Any insights here? Ultimately, I would like to create nrepl middleware for i) > Clojurescript compilation (cljsbuild auto (yes, I've already looked at > hiredman/nrepl-cljs-middleware)) and ii) a browser-connected repl (cljsbuild > repl-listen). I want to have these facilities in a `M-x nrepl-jack-in` > session. > > > A) basic nrepl middleware > > project.clj (https://www.refheap.com/paste/7875) > middleware.clj (https://www.refheap.com/paste/7874) > client.clj (https://www.refheap.com/paste/7876) > > B) lein repl > > $ lein new thing > ... > $ cd thing/ > $ lein repl > > nREPL server started on port 38789 > ... > user=> (require '[clojure.tools.nrepl :as repl]) > nil > > user=> > user=> (with-open [conn (repl/connect :port 38789)] > #_=> (-> (repl/client conn 1000) > #_=> (repl/message {:op "eval" :code "(+ 2 3)"}) > #_=> repl/response-values)) > > Exception in thread "nREPL-worker-2" nil > user=> java.net.SocketException: Broken pipe > at java.net.SocketOutputStream.socketWrite0(Native Method) > at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) > at java.net.SocketOutputStream.write(SocketOutputStream.java:136) > at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) > at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123) > at clojure.tools.nrepl.transport$bencode$fn__214.invoke(transport.clj:81) > at clojure.tools.nrepl.transport.FnTransport.send(transport.clj:27) > at > clojure.tools.nrepl.middleware.pr_values$pr_values$fn$reify__479.send(pr_values.clj:23) > at > clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__536$fn__538.invoke(interruptible_eval.clj:171) > at clojure.core$comp$fn__4034.invoke(core.clj:2278) > at > clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__529.invoke(interruptible_eval.clj:137) > at clojure.lang.AFn.run(AFn.java:24) > at > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:619) > > > > Thanks in advance > > Tim Washington > Interruptsoftware.ca > > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en