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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -