Created
November 13, 2013 03:51
-
-
Save MarcoPolo/7443411 to your computer and use it in GitHub Desktop.
work load balancing in servant: http://marcopolo.io/2013/10/01/servant-cljs.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(go | |
;; Get a worker from the buffered channel | |
(let [worker (<! servant-channel)] | |
;; execute the post message for the web worker | |
(post-message-fn worker (pr-str fn-key) args) | |
;; Add an event listener for the worker's return message | |
(.addEventListener worker "message" | |
#(go | |
;; Save the data | |
(>! out-channel (.-data %1)) | |
;; return the worker back to the servant-channel | |
(>! servant-channel worker))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When there are no more workers available in the pool, the code will "block" until a worker is free.