|
26 | 26 | "Starts the nrepl-server in async mode according to `OPTS`, using a
|
27 | 27 | asyncio task to schedule any pending client work every 100ms.
|
28 | 28 |
|
29 |
| - `OPTS` is a map that can have the following keys |
| 29 | + `OPTS` is a map that can have the following keys. It defaults to {}. |
30 | 30 |
|
31 | 31 | `:dir` The directory where the `.nrepl-port` file should be created
|
32 | 32 | at. It defaults to the current working directory if not given or
|
|
49 | 49 | connections.
|
50 | 50 |
|
51 | 51 | `:shutdown!` A function to shutdown the server."
|
52 |
| - [{:keys [host port dir interval-sec] :as opts |
53 |
| - :or {port 0 |
54 |
| - interval-sec 0.1}}] |
55 |
| - (let [host (if (or (nil? host) (empty? (str/trim host))) |
56 |
| - "127.0.0.1" |
57 |
| - host) |
58 |
| - nrepl-port-dir (if (or (nil? dir) (empty? (str/trim dir))) |
59 |
| - "." |
60 |
| - dir)] |
| 52 | + ([] |
| 53 | + (server-start {})) |
| 54 | + ([{:keys [host port dir interval-sec] :as opts |
| 55 | + :or {port 0 |
| 56 | + interval-sec 0.1}}] |
| 57 | + (let [host (if (or (nil? host) (empty? (str/trim host))) |
| 58 | + "127.0.0.1" |
| 59 | + host) |
| 60 | + nrepl-port-dir (if (or (nil? dir) (empty? (str/trim dir))) |
| 61 | + "." |
| 62 | + dir)] |
61 | 63 |
|
62 |
| - (if (not (os.path/isdir nrepl-port-dir)) |
63 |
| - {:error (u/error-make [:nrepl-server-start :nrepl-port-dir-not-a-dir nrepl-port-dir])} |
| 64 | + (if (not (os.path/isdir nrepl-port-dir)) |
| 65 | + {:error (u/error-make [:nrepl-server-start :nrepl-port-dir-not-a-dir nrepl-port-dir])} |
64 | 66 |
|
65 |
| - (let [{:keys [error work-fn shutdown-fn] :as ret} |
66 |
| - (nr/server-start! {:async? true |
67 |
| - :host host |
68 |
| - :port port |
69 |
| - :nrepl-port-file (os.path/join nrepl-port-dir ".nrepl-port")})] |
70 |
| - (if error |
71 |
| - (binding [*out* sys/stderr] |
72 |
| - (println :server-start-error (u/error->str error)) |
73 |
| - {:error error}) |
| 67 | + (let [{:keys [error work-fn shutdown-fn] :as ret} |
| 68 | + (nr/server-start! {:async? true |
| 69 | + :host host |
| 70 | + :port port |
| 71 | + :nrepl-port-file (os.path/join nrepl-port-dir ".nrepl-port")})] |
| 72 | + (if error |
| 73 | + (binding [*out* sys/stderr] |
| 74 | + (println :server-start-error (u/error->str error)) |
| 75 | + {:error error}) |
74 | 76 |
|
75 |
| - (let [shutdown?* (volatile! false) |
76 |
| - shutdown! #(do (vreset! shutdown?* true) |
77 |
| - (shutdown-fn) |
78 |
| - :shut) |
79 |
| - loop (asyncio/get-running-loop) |
80 |
| - task (.create-task loop (work-task interval-sec work-fn shutdown?* shutdown!))] |
81 |
| - (-> (select-keys ret [:host :port :nrepl-port-file]) |
82 |
| - (assoc :shutdown! shutdown! |
83 |
| - :_task task)))))))) |
| 77 | + (let [shutdown?* (volatile! false) |
| 78 | + shutdown! #(do (vreset! shutdown?* true) |
| 79 | + (shutdown-fn) |
| 80 | + :shut) |
| 81 | + loop (asyncio/get-running-loop) |
| 82 | + task (.create-task loop (work-task interval-sec work-fn shutdown?* shutdown!))] |
| 83 | + (-> (select-keys ret [:host :port :nrepl-port-file]) |
| 84 | + (assoc :shutdown! shutdown! |
| 85 | + :_task task))))))))) |
84 | 86 |
|
85 | 87 | (defn ^:inline server-shut
|
86 | 88 | "Convenience function to shutdown the `SERVER`."
|
|
0 commit comments