https://github.com/federkasten/butler
Bring Web Workers to ClojureScript
https://github.com/federkasten/butler
clojurescript webworkers
Last synced: 19 days ago
JSON representation
Bring Web Workers to ClojureScript
- Host: GitHub
- URL: https://github.com/federkasten/butler
- Owner: federkasten
- License: apache-2.0
- Created: 2014-05-28T10:17:00.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-01-31T11:12:11.000Z (about 9 years ago)
- Last Synced: 2025-03-26T20:22:31.221Z (about 1 month ago)
- Topics: clojurescript, webworkers
- Language: Clojure
- Homepage:
- Size: 24.4 KB
- Stars: 48
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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!`;
```clj
(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`;
```clj
(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](https://github.com/federkasten/butler/tree/master/example) for more details.
## License
Copyright [Takashi AOKI][tak.sh] and other contributors.
Licensed under the [Apache License, Version 2.0][apache-license-2.0].
[tak.sh]: http://tak.sh
[apache-license-2.0]: http://www.apache.org/licenses/LICENSE-2.0.html