Reading input stream within future


#1

I have a need to read a data from a stream provided by clj-http; what I do now is that I use line-seq https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L3077 to “unbundle” the stream to a lazy sequence of lines, that in turn are processed by a transducer.

This works, but sometimes the other party stalls - keeps the socket open (so I get no exception on my end) but sends nothing anymore. So I would like to raise an exception - or send a “poison pill” - if nothing is read after say one minute.

What I was wondering, is it safe to read from a BufferedReader within a future (that will happen in a different thread), so I can write my own line-seq that does the .readLine in a future, and if the future does not reply in one minute, it goes boom?