ring

jf 2024-06-02T14:49:39.142119Z

could somebody enlighten me as to how I would use the callbacks for WebSocket send async? Specifically: • if succeed does not have any arguments, how does it know would which send operation it is success for? • similarly for fail

weavejester 2024-06-04T10:16:16.739369Z

Yep, as hiredman says, use a closure. For example:

(defn send-greetings [socket name]
  (ws/send socket (str "Hello " name)
           (fn [] (println "Succeeded in greeting" name))
           (fn [_ex] (println "Failed in greeting" name))))
There's also https://github.com/ring-clojure/ring-websocket-async, which allows you to use core.async for a more convenient way of writing async code.

🙏 1
2024-06-03T18:31:07.694929Z

a closure can close over any needed state

👌 1