Skip to content

Commit

Permalink
Set version to 6.1.431
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Feb 3, 2022
1 parent 3804115 commit f12673c
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 34 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog #

## Version 6.1.x

Date: 2022-02-03

- Add `->` and `->>` threading macros (thanks to @wilkerlucio)



## Version 6.0.2

Date: 2021-06-01
Expand Down
54 changes: 54 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(ns build
(:refer-clojure :exclude [compile])
(:require
[clojure.tools.build.api :as b]
[cljs.build.api :as api]))

(def lib 'funcool/promesa)
(def version (format "6.1.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))

(defn clean [_]
(b/delete {:path "target"}))

(defn jar [_]
(b/write-pom
{:class-dir class-dir
:lib lib
:version version
:basis basis
:src-dirs ["src"]})

(b/copy-dir
{:src-dirs ["src" "resources"]
:target-dir class-dir})

(b/jar
{:class-dir class-dir
:jar-file jar-file}))

(defn clojars [_]
(b/process
{:command-args ["mvn"
"deploy:deploy-file"
(str "-Dfile=" jar-file)
"-DpomFile=target/classes/META-INF/maven/funcool/promesa/pom.xml"
"-DrepositoryId=clojars"
"-Durl=https://clojars.org/repo/"]}))

(def build-options
{:main 'promesa.tests.main
:output-to "target/tests.js"
:output-dir "target/tests"
:source-map "target/tests.js.map"
:target :nodejs
:optimizations :simple
:pretty-print true
:pseudo-names true
:verbose true})

(defn build-cljs-tests
[_]
(api/build (api/inputs "src" "test") build-options))
43 changes: 23 additions & 20 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
:aliases
{:dev
{:extra-deps
{com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"},
com.bhauman/rebel-readline {:mvn/version "0.1.4"},
{com.bhauman/rebel-readline-cljs {:mvn/version "RELEASE"},
com.bhauman/rebel-readline {:mvn/version "RELEASE"},
org.clojure/tools.namespace {:mvn/version "RELEASE"},
org.clojure/clojurescript {:mvn/version "1.10.866"},
org.clojure/clojurescript {:mvn/version "RELEASE"},
org.clojure/clojure {:mvn/version "1.10.3"},
criterium/criterium {:mvn/version "0.4.5"}}
:extra-paths ["test" "dev"]},
criterium/criterium {:mvn/version "RELEASE"}}
:extra-paths ["test" "dev" "src"]},

:repl
{:main-opts ["-m" "rebel-readline.main"]}

:test
{:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
{:git/url "https://github.com/cognitect-labs/test-runner.git"
:sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
:exec-fn cognitect.test-runner.api/test}
:extra-deps
{io.github.cognitect-labs/test-runner
{:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
:exec-fn cognitect.test-runner.api/test
:exec-args {:patterns [".*-test.*"]}}

:codox
{:extra-deps {codox/codox {:mvn/version "RELEASE"}
org.clojure/tools.reader {:mvn/version "RELEASE"}
codox-theme-rdash/codox-theme-rdash {:mvn/version "RELEASE"}}}
{:extra-deps
{codox/codox {:mvn/version "RELEASE"}
org.clojure/tools.reader {:mvn/version "RELEASE"}
codox-theme-rdash/codox-theme-rdash {:mvn/version "RELEASE"}}}

:outdated
{:extra-deps {com.github.liquidz/antq {:mvn/version "RELEASE"}
org.slf4j/slf4j-nop {:mvn/version "RELEASE"}}
:main-opts ["-m" "antq.core"]}
:build
{:extra-deps
{io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "34727f7"}}
:ns-default build}

:jar
{:replace-deps {com.github.seancorfield/depstar {:mvn/version "RELEASE"}}
:exec-fn hf.depstar/jar
:exec-args {:jar "target/promesa.jar"}}}}
:outdated
{:extra-deps
{com.github.liquidz/antq {:mvn/version "RELEASE"}
org.slf4j/slf4j-nop {:mvn/version "RELEASE"}}
:main-opts ["-m" "antq.core"]}}}
66 changes: 52 additions & 14 deletions doc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ A promise library for Clojure and ClojureScript.
Leiningen:

```clojure
[funcool/promesa "6.0.2"]
[funcool/promesa "6.1.431"]
```

deps.edn:

```clojure
funcool/promesa {:mvn/version "6.0.2"}
funcool/promesa {:mvn/version "6.1.431"}
```

On the JVM platform _promesa_ is built on top of *completable futures*
(requires JDK >= 8). On JS engines it is built on top of the execution
environment's built-in Promise implementation.



## Introduction

A promise is an abstraction that represents the result of an asynchronous
Expand Down Expand Up @@ -158,9 +157,10 @@ await and unwrap the inner promise:
;; => 1
```


## Promise Chaining

### `then`

The most common way to chain a transformation to a promise is using
the general purpose `then` function:

Expand All @@ -183,6 +183,8 @@ will automatically be flattened).
plain values, you can use the more performant `then'` variant of this
function.

### `map`

The `map` function works similarly to the `then'` function, the
difference is the order of arguments:

Expand All @@ -195,6 +197,8 @@ difference is the order of arguments:
;; => 2
```

### `chain`

If you have multiple transformations and you want to apply them in one
step, there are the `chain` and `chain'` functions:

Expand All @@ -210,6 +214,37 @@ step, there are the `chain` and `chain'` functions:
**NOTE**: these are analogous to `then` and `then'` but accept
multiple transformation functions.


### `->` and `->>`

NOTE: introduced in 6.1.431

This threading macros simplifices chaining operation, removing the
need of using `then` all the time.

Lets look an example using `then` and later see how it can be improved
using the `->` threading macro:

```clojure
(-> (p/resolved {:a 1 :c 3})
(p/then #(assoc % :b 2))
(p/then #(dissoc % :c)))
```

Then, the same code can be simplified with:

```clojure
(p/-> (p/resolved {:a 1 :c 3})
(assoc :b 2))
(dissoc :c))
```

The threading macros hides all the accidental complexity of using
promise chaining.


### `handle`

If you want to handle rejected and resolved callbacks in one unique
callback, then you can use the `handle` chain function:

Expand All @@ -224,6 +259,9 @@ callback, then you can use the `handle` chain function:
;; => :resolved
```


### `finally`

And finally if you want to attach a (potentially side-effectful)
callback to be always executed notwithstanding if the promise is
rejected or resolved, there is a executed regardless of whether the
Expand Down Expand Up @@ -256,14 +294,14 @@ while using the Clojure's familiar `let` syntax:
'[promesa.exec :as exec])

;; A function that emulates asynchronos behavior.
(defn sleep-promise
(defn sleep
[wait]
(p/promise (fn [resolve reject]
(exec/schedule! wait #(resolve wait)))))
(p/create (fn [resolve reject]
(exec/schedule! wait #(resolve wait)))))

(def result
(p/let [x (sleep-promise 42)
y (sleep-promise 41)
(p/let [x (sleep 42)
y (sleep 41)
z 2]
(+ x y z)))

Expand All @@ -279,8 +317,8 @@ exceptionally resolved promise.
Under the hood, the `let` macro evalutes to something like this:

```clojure
(p/then (sleep-promise 42)
(fn [x] (p/then (sleep-promise 41)
(p/then (sleep 42)
(fn [x] (p/then (sleep 41)
(fn [y] (p/then 2 (fn [z]
(p/promise (do (+ x y z)))))))))
```
Expand Down Expand Up @@ -574,14 +612,14 @@ To run the tests execute the following:
For the JVM platform:

```
lein test
clojure -X:dev:test
```

And for JS platform:

```
./scripts/build
node out/tests.js
clojure -A:dev -T:build build-cljs-tests
node target/tests.js
```

You will need to have Node.js installed on your system.
Expand Down

0 comments on commit f12673c

Please sign in to comment.