<commit_before># cljs-promises

A ClojureScript library for working with JavaScript promises.

## Requirements

Some functions in this library require that you've already got an ES6 Promise implementation present, either natively or through a [polyfill](https://github.com/jakearchibald/es6-promise). Other functions only require that you're giving them [Promises/A+](http://promises-aplus.github.io/promises-spec/)-compliant objects.

## Overview

This library leverages the power of 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 use a function which makes it so that values taken from promises 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 `<!`. If the `error` slot of the pair is non-nil, it throws the error. Otherwise it returns whatever is in the `value` slot.<commit_msg>readme: link to core.async<commit_after># cljs-promises

A ClojureScript library for working with JavaScript promises.

## Requirements

Some functions in this library require that you've already got an ES6 Promise implementation present, either natively or through a [polyfill](https://github.com/jakearchibald/es6-promise). Other functions only require that you're giving them [Promises/A+](http://promises-aplus.github.io/promises-spec/)-compliant objects.

## 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 use a function which makes it so that values taken from promises 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 `<!`. If the `error` slot of the pair is non-nil, it throws the error. Otherwise it returns whatever is in the `value` slot.
{'fraction_non_alphanumeric': 0.09690157958687728, 'fraction_numerical': 0.001215066828675577, 'mean_word_length': 4.571912013536379, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7669851', 'n_tokens_mistral': 925, 'n_tokens_neox': 886, 'n_words': 418}