funcool / promesa

A promise library & concurrency toolkit for Clojure and ClojureScript.
https://funcool.github.io/promesa/latest/
Mozilla Public License 2.0
498 stars 58 forks source link
async-await asynchronous-programming clojure clojurescript completablefuture concurrency deferred non-blocking promises threads virtual-threads

promesa

Clojars Project

A promise library & concurrency toolkit for Clojure and ClojureScript.

This library exposes a bunch of usefull syntactic abstractions that will considerably simplify to work with promises (in a very similar way as you will do it in JS with async/await) and many helpers from executors to concurrency patterns (bulkhead & CSP). With 0 runtime external dependencies.

Here you can look a detailed documentation.

Getting Started

deps.edn:

funcool/promesa {:mvn/version "11.0.678"}

Leiningen:

[funcool/promesa "11.0.678"]

On the REPL

(require '[promesa.core :as p])

(->> (p/promise 1)
     (p/map inc)
     (deref)
;; => 2

NOTE: example only work on JVM because the evident lack of blocking primitives on JS runtime.

Contributing

If you miss something, feel free to open an issue for a discussion. If there is a clear use case for the proposed enhacement, the PR will be more than welcome.

Testing

Run the Clojure (.clj) tests:

clojure -X:dev:test

Run the ClojureScript (.cljs) tests:

npm install
npm test