Fork me on GitHub

Anyone know how I might implement a file tailer in cljs+planck?


I had something close to working by re-opening a reader each time through a loop, but that just re-prints the whole file again rather than what's new.


(so not that close to working, haha)


@cap10morgan Hrm. This works in Clojure

(let [r (io/reader "/tmp/foo.txt")]
(loop [line (.readLine r)]
  (if (nil? line)
    (Thread/sleep 1000)
    (println line))
   (recur (.readLine r))))
but the translation to Planck doesn't pan out. I'm logging a ticket. I think the subtle difference might be that once a reader in Planck returns nil things are closed and it will always do so. But arguably it should behave like Clojure and return nil only when there is no line or somesuch (I haven't dug into the details)


@mfikes Interesting. I got something hacky working by keeping track of line counts in an atom and skipping that many the next time through the loop. But I'll happily keep an eye on that ticket to revert to something saner in the future. 🙂


I'm doing this in the first place as a hacky workaround for I redirect out and err of the command to a couple of tempfiles and run it from sh-async, then I tail those files to *out* and *err* until my sh-async callback gets called.


kinda gross but it works (so far)


@cap10morgan Yep, I also thought of issue 54 right away as well 🙂


I've also logged a ticket for the ability to sleep


ah cool. I've been doing ( "sleep" "1") 😁


Yep, that was also my reaction 🙂 I see no problem with that being directly in planck.core


(That way you can have more fine-grained control on how long to sleep


I have to say, overall, having converted a unwieldy bash script to cljs+planck, I am loving it. Kudos!


Sweet! And if you ever need to convert to Clojure, if you use aliases for the planck namespaces, it is nice that the API is very similar to Clojure.


I forgot I had also written this off in a side branch. I vaguely recall it being able to block. Hrm. :thinking_face: