1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-12 22:37:42 +00:00

More work on timeouts and racing listeners.

When two listeners are racing to resume the same fiber, the
first should cancel out the other.
This commit is contained in:
Calvin Rose
2020-07-05 17:26:17 -05:00
parent a4de83b3a3
commit 9ba94d2c6b
5 changed files with 119 additions and 39 deletions

View File

@@ -5,10 +5,17 @@
(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))
(defn spawn-kid
"Run handler in a new fiber"
[conn]
(def f (fiber/new handler))
(ev/go f conn))
(print "Starting echo server on 127.0.0.1:8000")
(def server (net/server "127.0.0.1" "8000"))
@@ -16,4 +23,5 @@
# Run server.
(while true
(with [conn (:accept server)]
(handler conn)))
(spawn-kid conn)
(ev/sleep 0.1)))