Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zachallaun/async-pipeline


https://github.com/zachallaun/async-pipeline

Last synced: 3 days ago
JSON representation

Awesome Lists containing this project

README

        

# async-pipeline

A small library for creating `clojure.core.async` process pipelines.

_Inspired by [Messaging as a Programming Model](http://eventuallyconsistent.net/2013/08/12/messaging-as-a-programming-model-part-1/)._

```clj
(require '[clojure.core.async :as async :refer [>! ! out msg)
(recur))
[:error :invalid-credentials msg])))))

(defn filter-api-key-enabled
[in out]
(go-try
(loop []
(when-recv [{:keys [api-key] :as msg} (! out (assoc msg :api-details details))
(recur))
[:error :invalid-api-key msg])))))

(defn get-user-info
[in out]
(go-try
(loop []
(when-recv [{:keys [username api-details] :as msg} (! out (assoc msg :user-info (user-info-for username api-details)))
(recur)))))

(def login-pipeline
(pipeline async/chan
filter-valid-credentials
filter-api-key-enabled
get-user-info))

(let [[in out err ctrl] login-pipeline]
(forward-login-requests in)
(handle-login-errors err)
(respond-with-details out)

(async/put! in {:username "zach" :password "p@$$w04d"}))
```