Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamesmacaulay/cljs-promises
A ClojureScript library for using JS promises with core.async
https://github.com/jamesmacaulay/cljs-promises
Last synced: 24 days ago
JSON representation
A ClojureScript library for using JS promises with core.async
- Host: GitHub
- URL: https://github.com/jamesmacaulay/cljs-promises
- Owner: jamesmacaulay
- License: mit
- Created: 2014-04-03T03:28:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-15T06:53:21.000Z (about 8 years ago)
- Last Synced: 2024-09-12T22:51:01.181Z (2 months ago)
- Language: Clojure
- Size: 172 KB
- Stars: 90
- Watchers: 6
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cljs-promises
A ClojureScript library for working with JavaScript promises.
### Overview
This library leverages the power of [core.async](https://github.com/clojure/core.async) to let you write promise code like this:
```clojure
(cljs-promises.async/extend-promises-as-pair-channels!)(go
(let [user-promise (get-user "jamesmacaulay")]
(try
(println (:blog ( user-promise)))
(catch js/Error e
(println (str "Could't get user data: " (ex-message e))))))
```The first line globally extends `Promise` instances to act like **read-only channels** which, once resolved, **endlessly produce the same value or error to anyone who takes from them**. Because promises have built-in error semantics which don't have any direct corollary in core.async, there are different ways that we can represent promise results. In this example we've extended promises in a way that values taken from them with core.async are actually `[value error]` pairs, where you get `[value nil]` from a fulfilled promise and `[nil error]` from a rejected promise.
`` is a macro provided by `cljs-promises.async` which takes one of these pairs from a promise with core.async's `