Skip to content

federkasten/butler

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

butler

Bring Web Workers to ClojureScript

  • Simple API
  • Suitable for Clojure data structure
  • Support transferable objects

Usage

Add the following dependency to your project.clj:

[butler "0.2.0"]

Example

Create web workers and define its response handlers in main thread, and tell to workers via work!;

(require '[butler.core :as butler])

(enable-console-print!)

;; Create a web worker with script and handlers.
(def example-butler (butler/butler "path/to/worker.js" {:foo (fn [res]
                                                               (println res))}))

(butler/work! example-butler :request-foo "foo")

In worker threads, define handlers of requests using serve! and send results to the main thread using bring;

(require '[butler.core :as butler])

(defn run-foo [req]
  ;; some heavy heavy jobs
  (butler/bring! :foo "hello"))

(def handlers {:request-foo run-foo})

(butler/serve! handlers)

See example for more details.

License

Copyright Takashi AOKI and other contributors.

Licensed under the Apache License, Version 2.0.