Skip to content

Instantly share code, notes, and snippets.

@curist
Created September 5, 2019 14:40
Show Gist options
  • Save curist/eee262729ec0418042ddc02dbbbc0db4 to your computer and use it in GitHub Desktop.
Save curist/eee262729ec0418042ddc02dbbbc0db4 to your computer and use it in GitHub Desktop.
(import uv)
(def host "127.0.0.1")
(def port 10043)
(def server (uv/tcp/new))
(defn handler [&]
(def client (uv/tcp/new))
(print "connected")
(pp client)
(:accept server client)
(yield (:write client "repl server connected"))
(:read-start client)
(defn chunks [buf p]
(pp :read-chunk)
(var chunk nil)
(while true
(set chunk (yield))
(if (nil? chunk)
(pp :read-no-chunk)
(break)))
(pp (type chunk))
(pp chunk)
(buffer/push-string buf chunk)
(pp :read-chunk-end))
(defn onsignal [f x]
(pp :onsignal)
(def status (fiber/status f))
(case status
:dead (do
(pp :dead)
(:write client (string x)))
:error (debug/stacktrace f x)
(do
(pp :status)
(pp status))))
(defn oncompileerror [msg errf where]
(pp :compile-err)
(:write client (string where ": " msg)))
(defn onbadparse [p where]
(pp :parse-err)
(:write client "parse err"))
(run-context {:env (make-env)
:chunks chunks
:on-status onsignal
:on-compile-error oncompileerror
:on-parse-error onbadparse
:source "remote-repl"})
)
(uv/enter-loop
(print "server started " (os/clock))
(:bind server host port)
(:listen server handler))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment