Skip to content

Instantly share code, notes, and snippets.

@MarcoPolo
Created November 13, 2013 03:51
Show Gist options
  • Save MarcoPolo/7443411 to your computer and use it in GitHub Desktop.
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
(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)))))
@MarcoPolo
Copy link
Author

When there are no more workers available in the pool, the code will "block" until a worker is free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment