Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
Created June 12, 2012 02:36
Show Gist options
  • Save ohpauleez/2914039 to your computer and use it in GitHub Desktop.
Save ohpauleez/2914039 to your computer and use it in GitHub Desktop.
Shoreleave's Web Workers
(ns barker.client.main
(:require [shoreleave.client.worker :as swk]))
; Take any function in your source...
(defn echo-workerfn [data] data)
; Drop it into a worker...
(def nw (swk/worker echo-workerfn))
; The worker implements IWatchable
(add-watch nw :watcher #(js/console.log (last %4)))
; And you can also deref it, but think about it... that's a terrible idea usually
; (js/console.log (apply str @nw))
(nw "HELLO")
(nw "THREADS")
(comment
The console shows:
HELLO barker.js:23161
THREADS barker.js:23161
That line is the add-watch anon func
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment