planck

Planck ClojureScript REPL
cap10morgan 2017-11-28T20:48:11.000174Z

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

cap10morgan 2017-11-28T20:50:05.000354Z

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.

cap10morgan 2017-11-28T20:59:32.000348Z

(so not that close to working, haha)

mfikes 2017-11-28T21:42:10.000530Z

@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 2017-11-28T21:42:28.000530Z

This is based on https://stackoverflow.com/a/558262

cap10morgan 2017-11-28T21:44:33.000153Z

@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. 🙂

mfikes 2017-11-28T21:46:39.000217Z

@cap10morgan https://github.com/mfikes/planck/issues/557

👍 1
cap10morgan 2017-11-28T21:50:09.000039Z

I'm doing this in the first place as a hacky workaround for https://github.com/mfikes/planck/issues/54. 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.

cap10morgan 2017-11-28T21:50:23.000633Z

kinda gross but it works (so far)

mfikes 2017-11-28T21:52:27.000352Z

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

mfikes 2017-11-28T21:52:35.000259Z

I've also logged a ticket for the ability to sleep https://github.com/mfikes/planck/issues/558

cap10morgan 2017-11-28T21:53:26.000614Z

ah cool. I've been doing (planck.shell/sh "sleep" "1") 😁

mfikes 2017-11-28T21:53:46.000534Z

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

mfikes 2017-11-28T21:54:20.000422Z

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

cap10morgan 2017-11-28T21:54:44.000049Z

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

mfikes 2017-11-28T21:59:15.000442Z

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.

mfikes 2017-11-28T22:01:07.000010Z

I forgot I had also written this off in a side branch. I vaguely recall it being able to block. Hrm. :thinking_face: https://github.com/mfikes/planck/commit/f1b8547bf2a42bc06d04e81d52048555ba223c60