This re-frame library contains an web worker effect handler. The handler can be addressed by :worker
and wraps the API of cljs-workers.
Add the following dependency to your project.cljs
:
See the following minimal code example or the test.cljs. For general usage of workers see cljs-workers.
The following example presupposes that there is already a worker pool and registered worker-handler.
(ns your.project
(:require [re-frame.core :as re-frame]
[re-frame-worker-fx.core]))
(re-frame/reg-event-fx
:some-event
(fn [coeffects _]
(let [worker-pool
(-> coeffects :db :worker-pool)]
{:worker {:pool worker-pool
;; handler that will be called
:handler :your-worker-handler
;; arguments applied to the handler
:arguments {:a "Hallo Welt!" :b 10 :c (js/ArrayBuffer. 10)}
;; which arguments will be transfered instead of copied
:transfer [:c]
;; dispatched on success conjoined with the result
:on-success [:your-success-event]
;; dispatched on error conjoined with the result
:on-error [:your-error-event]}})))
I´d be thankful to receive patches, comments and constructive criticism.
Hope the package is useful :-)