Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't read new input unless we're done with the last repl message.

Rather than looping back to Readline.read after every "done" message,
we inspect the message and only do so if it's the result of a
top-level repl message. Without this we get input and output out of
sync when sending non-repl messages such as stdin or interrupt.

Fixes #11.
  • Loading branch information...
commit 5829cb56ee53ddd502f1585db3a157885e0feb01 1 parent 0f30ca9
@technomancy authored
Showing with 14 additions and 8 deletions.
  1. +3 −2 nrepl.ml
  2. +11 −6 repl.ml
View
5 nrepl.ml
@@ -101,9 +101,10 @@ let interrupt_message session id =
("interrupt-id", id)],
quiet_actions)
-(* TODO: input/values get out of sync when interrupts fire or on send-input *)
let interrupt session w p _ =
- send w p (interrupt_message session !current_msg_id)
+ match Hashtbl.keys p with
+ | ["init"] | [] -> Pervasives.exit 0
+ | _ -> send w p (interrupt_message session !current_msg_id)
let register_interrupt session w p =
Caml.Sys.signal Caml.Sys.sigint (Caml.Sys.Signal_handle (interrupt session w p))
View
17 repl.ml
@@ -13,18 +13,23 @@ let repl_message input session =
let dummy_message session =
([("session", session);
("op", "eval");
- ("id", "dummy");
+ ("id", "repl-dummy");
("ns", "user");
("code", "nil")],
Nrepl.default_actions)
+let repl_done = function
+ | Some Bencode.String(id) -> (String.sub id 0 5) = "repl-"
+ | Some _ | None -> false
+
let rec loop (r,w,p) resp =
let prompt = (!Client.ns ^ "=> ") in
- match Readline.read prompt, List.Assoc.find resp "session" with
- | Some input, Some Bencode.String(session) ->
- Nrepl.send w p (repl_message input session)
- | Some _, _ -> Printf.eprintf "Missing session.\n"; Pervasives.exit 1
- | None, _ -> Pervasives.exit 0
+ if repl_done (List.Assoc.find resp "id") then
+ match Readline.read prompt, List.Assoc.find resp "session" with
+ | Some input, Some Bencode.String(session) ->
+ Nrepl.send w p (repl_message input session)
+ | Some _, _ -> Printf.eprintf "Missing session.\n"; Pervasives.exit 1
+ | None, _ -> Pervasives.exit 0
let main port =
let handler = Client.handler loop in
Please sign in to comment.
Something went wrong with that request. Please try again.