Buffer outbound messages while waiting for connection

This commit is contained in:
Tony Garnock-Jones 2014-08-12 16:20:39 -07:00
parent 33251164b2
commit b380c9ca64
1 changed files with 10 additions and 3 deletions

View File

@ -126,10 +126,17 @@
(websocket-connection id local-addr remote-addr c control-ch))
(when (not (exn? c))
(connection-thread-loop control-ch c id))))
(actor (subscribe (websocket-connection id local-addr remote-addr ($ c) control-ch)
(actor #:state [buffered-messages-rev '()]
(subscribe (websocket-connection id local-addr remote-addr ($ c) control-ch)
#:meta-level 1
(list (when (not (exn? c)) (spawn-connection local-addr remote-addr id c control-ch))
(quit)))))
(list (when (not (exn? c))
(for [(m (reverse buffered-messages-rev))] (ws-send! c m))
(spawn-connection local-addr remote-addr id c control-ch))
(quit)))
(subscribe (websocket-message local-addr remote-addr ($ m))
#:update [buffered-messages-rev (cons m buffered-messages-rev)])))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Connection