clojurescript - Checking if a Clojure(Script) Channel is Full -


suppose c channel of size n. trying write function in clojure(script) checks see if c full and, if so, closes channel.

but how 1 check see whether channel full?

core.async offers pair of functions this:

  • offer! put on channel if space available, , let know if full.
  • poll! gets if it's available , lets know if channel has nothing offer @ moment.

so write like:

(if-not (offer! my-chan 42)    (close! my-chan)) 

which accomplish when putting on channel. safer trying have process watch moment get's full , close it. if want check if it's full can extract buffer , ask it:

user> (->> (async/chan (async/buffer 1))            (.buf)            (.full?)) false 

though think 1 through first.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -