mirror of
https://github.com/janet-lang/janet
synced 2024-10-31 22:16:16 +00:00
553b4d9428
Further debugging of the general timeout system, as well as having a single fiber wait on multiple state machines (select).
21 lines
558 B
Clojure
21 lines
558 B
Clojure
(defn handler
|
|
"Simple handler for connections."
|
|
[stream]
|
|
(defer (:close stream)
|
|
(def id (gensym))
|
|
(def b @"")
|
|
(print "Connection " id "!")
|
|
(while (:read stream 1024 b)
|
|
(repeat 10 (print "work for " id " ...") (ev/sleep 1))
|
|
(:write stream b)
|
|
(buffer/clear b))
|
|
(printf "Done %v!" id)))
|
|
|
|
# Run server.
|
|
(let [server (net/server "127.0.0.1" "8000")]
|
|
(print "Starting echo server on 127.0.0.1:8000")
|
|
(forever
|
|
(if-let [conn (:accept server 2.8)]
|
|
(ev/call handler conn)
|
|
(print "no new connections"))))
|