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:
@@ -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)))
|
||||
|
Reference in New Issue
Block a user