thanks for the tips @henryw374 @smith.adriane
I totally blanked on being able to run some-function
inside its own go block! That does make sense π
I ended up doing it like this first a tick channel which prevents drifts over time then later, use that tick channel with another function abstracted the drift-corrector-tick-channel since I expect that will come in handy for another thing too
(def tick-channel (chan))
(def tick-interval-ms 50)
(let [start-time (js/Date.now)]
(go-loop [i 1]
(let [delay (- (+ start-time (* i tick-interval-ms))
(js/Date.now))]
(<! (timeout delay))
(>! tick-channel i))
(recur (inc i))))
(go-loop []
(<! tick-channel)
(some-function))
@smith.adriane, if I am calculating delay like this anyways, would it be necessary to have some-function
be in a separate go block?
@baibhavbista Doing regular ticks without drift involves a whole bunch of things, like performance.now()
and document.timeline
, and that's just with plain JS. Jake Archibald https://gist.github.com/jakearchibald/cb03f15670817001b1157e62a076fe95. And here's https://www.youtube.com/watch?v=MCi6AZMkxcU. This can be done through ClojureScript using JS interop.
Hope this helps.
it depends on what some-function
is.
β’ will it always execute within the delay?
β’ what if there's a bug in some-function
at some point?
β’ should multiple copies of some-function
be allowed to run at once? if so, how many?
basically, it comes down to thinking about what might go wrong in the future as the code changes and planning how to fail gracefully if the best thing doesn't always happen.
there's also a question of what happens if some-function
throws an exception. should the repeating work continue? what if it keeps failing? etc.
also. I never want to miss an opportunity to recommend reading http://erlang.org/download/armstrong_thesis_2003.pdf
Quick question. In clojure you can specify the print function for the repl by evaluating (clojure.main/repl :print clojure.pprint/pprint))
I canβt for the life of me find the clojurescript equivalent. Iβve tried (cljs.repl/repl :print cljs.pprint/pprint))
but cljs.repl/repl isnβt available. Any ideas?
Iβm just running the basic cljs repl from the webpack clojurescript tutorial.
I am trying to get a clojurescript environment set up on a macos machine.
1/Cursive seems not to be working with the latest IDEA: every Clojure keyword in a source file shows up as cannot be resolved
. I was able to get a remote Cursive REPL to work with shadow-cljs. The REPL works fine, just the editing is off.
2/I've been trying to get CIDER working. Highlighting works fine, but every time I try to jack-in I get the message could not start nREPL server: env: node: no such file or directory
. And yes I do have node set up and on the emacs exec path.
Any suggestions as to where I can turn next? Thanks!
Just in case - perhaps the issue you had with Cursive has been fixed: https://clojurians.slack.com/archives/C06MAR553/p1614090076040800