This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-25
Channels
Given a string s, I want to convert s to a flow that emits each character of s sequentially every 100ms. Here is my attempt at it:
(let [s "dummy-string"
!val (atom "")]
((fn [i]
(when (< i (count msg))
(reset! !val (subs s i))))
(- (int (/ e/system-time-ms 100))
(int (/ (e/snapshot e/system-time-ms) 100)))))
This works when you load the page, but if I place this in an e/fn, the snippet doesn't work. It makes sense as e/system-time-ms won't be referenced multiple times. How best to resolve this?my idea is to use (m/seed “dummy”) to create a discrete flow of chars, and then consume it slowly, perhaps by creating another discrete flow of ticks and then figuring out how to alternate them
broadly, i think discrete things are best modeled in missionary not electric
(defn delayed-seed [d xs]
(m/ap (m/? (m/sleep d (m/?> (m/seed xs))))))
((->> "hello"
(delayed-seed 1000)
(m/reduce (fn [_ x] (prn x)) nil))
#(prn :success %) #(prn :failure %))
m/sleep solutions all drift don’t they?
(defn fixed-rate-seed [d xs]
(m/ap (let [[x t] (m/?> (m/seed (map vector xs (iterate (partial + d) (System/currentTimeMillis)))))]
(m/? (m/sleep (- t (System/currentTimeMillis)) x)))))
what is the difference between fixed-rate-seed and delayed seed? i don't think i understand "drift"
in java, (thread/sleep N) will sleep at least N seconds, generally a couple ms over, so if you repeat these sleeps you’ll drift away from a true clock
a couple ms per tick
the corrected ticker, which leo shows, uses platform sleep (which is blurry) but then measures how long it actually took, thus adjusting for the variance
Here is the full e/fn
snippet for context. api is https://github.com/wkok/openai-clojure