Skip to content

Instantly share code, notes, and snippets.

@twashing
Created July 18, 2018 00:42
Show Gist options
  • Save twashing/8da19cb30ff7bca6ed346d2a9a97e699 to your computer and use it in GitHub Desktop.
Save twashing/8da19cb30ff7bca6ed346d2a9a97e699 to your computer and use it in GitHub Desktop.
(require
'[clojure.core.async :refer [chan sliding-buffer <! go-loop onto-chan] :as async]
'[manifold.stream :as stream]
'[prpr.stream.cross :as stream.cross])
(let [tick-list->macd-ch (chan (sliding-buffer 50))
sma-list->macd-ch (chan (sliding-buffer 50))
tick-list->MACD (->> tick-list->macd-ch
stream/->source
(stream.cross/event-source->sorted-stream :id))
sma-list->MACD (->> sma-list->macd-ch
stream/->source
(stream.cross/event-source->sorted-stream :id))
result (stream.cross/set-streams-union {:default-key-fn :id
:skey-streams {:tick-list tick-list->MACD
:sma-list sma-list->MACD}})
connector-ch (chan (sliding-buffer 100))]
;; OK
#_(go-loop [r (<! tick-list->macd-ch)]
(info r)
(when r
(recur (<! tick-list->macd-ch))))
;; OK
#_(stream/map (fn [r]
(prn ">> " r)
r)
sma-list->MACD)
(stream/connect @result connector-ch)
(go-loop [{:keys [tick-list sma-list] :as r} (<! connector-ch)]
(info "record: " r)
(if-not r
r
(recur (<! connector-ch))))
(onto-chan tick-list->macd-ch [{:id :a :val 1} {:id :b :val 2} {:id :c :val 3}])
(onto-chan sma-list->macd-ch [{:id :a :val 2} {:id :b :val 3} {:id :c :val 4}]))
@twashing
Copy link
Author

I seem to have gotten a bit further with [employeerepublic/promisespromises "0.5"], which works with [manifold "0.1.7-alpha6"].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment