fukamachi / event-emitter

Event mechanism for Common Lisp objects.
BSD 2-Clause "Simplified" License
28 stars 8 forks source link

t instead of T in event-emitter:emit #7

Closed plops closed 5 years ago

plops commented 5 years ago

I tried clack with websocket-driver to create a websocket server:

(mapc #'ql:quickload '("clack" "websocket-driver"
               "event-emitter"))
(defparameter *wss-port* 7778)
(defun ws-handler (env)
  (destructuring-bind (&key request-uri remote-addr remote-port content-type content-length &allow-other-keys)
      env
    (let ((ws (websocket-driver:make-server env)))
      (event-emitter:on :message ws
            (lambda (message)
              (websocket-driver:send ws message)))
      (lambda (responder)
    (websocket-driver:start-connection ws)))))
(clack:clackup
 (lambda (env)
   (funcall 'ws-handler env))
 :port *wss-port*
 :ssl t :ssl-key-file  #P"/tmp/server.key" :ssl-cert-file #P"/tmp/server.crt"
 :use-default-middlewares nil)

When it receives a message, it throws this error:

The variable event-emitter::T is unbound. [Condition of type unbound-variable]

Restarts: 0: [continue] Retry using event-emitter::T. 1: [use-value] Use specified value. 2: [store-value] Set specified value and use it. 3: [abort] abort thread (#<thread "hunchentoot-worker-127.0.0.1:37494" running {1001897CD3}>)

I fixed it by changing the return value of this function from T to t.

(defun emit (event object &rest args)
  (let ((listeners (listeners object event)))
    (when (zerop (length listeners))
      (return-from emit nil))

    (map nil (lambda (listener)
             (let ((fn (listener-function listener)))
               (apply fn args)
               (when (listener-once listener)
                 (remove-listener object event fn))))
         listeners)
    t))  ;;;  <---- error?
fukamachi commented 5 years ago

Do you set *print-case* downcase?

plops commented 5 years ago

Oops, yes. I use downcase for the sexpr to Javascript converter.