1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-12 06:17:43 +00:00

Merge pull request #1615 from ifreund/net-server-datagram

net/server: improve error for truthy handler and type :datagram
This commit is contained in:
Calvin Rose
2025-08-02 18:06:24 -05:00
committed by GitHub

View File

@@ -3919,8 +3919,14 @@
(compwhen (dyn 'net/listen)
(defn net/server
"Start a server asynchronously with `net/listen` and `net/accept-loop`. Returns the new server stream."
``
Starts a server with `net/listen`. Runs `net/accept-loop` asynchronously if
`handler` is set and `type` is `:stream` (the default). It is invalid to set
`handler` if `type` is `:datagram`. Returns the new server stream.
``
[host port &opt handler type no-reuse]
(assert (not (and (= type :datagram) handler))
"handler not supported for :datagram servers")
(def s (net/listen host port type no-reuse))
(if handler
(ev/go (fn [] (net/accept-loop s handler))))