From 67e03c673624616938ff3db45197dcb9474da07a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 3 Jul 2022 11:09:02 +0100 Subject: [PATCH] extract function --- socket-repl.fnl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/socket-repl.fnl b/socket-repl.fnl index da95a99..080c123 100644 --- a/socket-repl.fnl +++ b/socket-repl.fnl @@ -20,6 +20,12 @@ (on-connected connected-fd))) )) +(fn get-input [fd] + (let [buf (unistd.read fd 1024)] + (if (and buf (> (# buf) 0)) + buf + "\n,exit"))) + (fn start [pathname] (unistd.unlink pathname) (unix-socket-listener @@ -29,17 +35,11 @@ repl-coro (coroutine.create repl)] (watch-fd fd fcntl.O_RDONLY (fn [fd] - (let [buf (unistd.read fd 1024) - input - (if (and buf (> (# buf) 0)) - buf - "\n,exit")] - (coroutine.resume repl-coro input)) + (coroutine.resume repl-coro (get-input fd)) (if (= (coroutine.status repl-coro) :dead) (do (sock:write "bye!\n") (sock:close) - (unistd.close fd) false) true )))