Skip to content

Instantly share code, notes, and snippets.

@tolitius
Created November 5, 2016 04:51
Show Gist options
  • Save tolitius/248fb389f65aeef0ef5e575ac0af5fcd to your computer and use it in GitHub Desktop.
Save tolitius/248fb389f65aeef0ef5e575ac0af5fcd to your computer and use it in GitHub Desktop.

repl time

$ boot repl

boot.user=> (require :reload '[pipeline :refer [engine]]
                             '[mount.core :as mount])
"|| mounting... #'pipeline/engine"

starting it

boot.user=> (mount/start)
{:started ["#'pipeline/engine"]}

running with it

boot.user=> ((engine :process) ["apple" "banana" "carrot"])

your word is: TORRAC
your word is: ELPPA
your word is: ANANAB


boot.user=> ((engine :process) ["do" "what" "makes" "sense"])

your word is: OD
your word is: TAHW
your word is: ESNES
your word is: SEKAM

stopping it

boot.user=> (mount/stop)
engine is stopped
{:stopped ["#'pipeline/engine"]}
(ns pipeline
(:require [clojure.core.async :as ca :refer [>! <!]]
[clojure.string :as s]
[mount.core :refer [defstate]]))
(defn upverse [from to]
(ca/pipeline-blocking 4
to
(map (comp s/upper-case
s/reverse))
from))
(defn produce [ch xs]
(doseq [word xs]
(ca/go (>! ch word))))
(defn consume [ch]
(ca/go-loop []
(when-let [word (<! ch)]
(println "your word is:" word)
(recur))))
(defn start-engine []
(let [[from to] [(ca/chan) (ca/chan)]]
(upverse to from)
(consume from)
{:stop (fn []
(ca/close! to)
(ca/close! from)
(println "engine is stopped"))
:process (partial produce to)}))
(defstate engine :start (start-engine)
:stop ((:stop engine)))
(def +version+ "0.0.1")
(set-env!
:source-paths #{"."}
:dependencies
'[[org.clojure/core.async "0.2.395"]
[org.clojure/clojure "1.8.0"]
[mount "0.1.10"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment