Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn snag-quotes [n]
- (let [c (chan)
- p (promise)]
- ;; Reading n items from the channel here. The vec is delivered
- ;; through a go-block result channel. There is also go-loop for
- ;; this:
- (go (loop [n n
- acc []]
- (if (zero? n)
- (do
- (show "x")
- (deliver p acc))
- (let [x (<! c)]
- (show "!")
- (recur (dec n)
- (conj acc x))))))
- ;; Posting to the channel here, each from a separate "thread". An
- ;; exception that prevents a put would deadlock the reader down
- ;; there:
- (dotimes [n n]
- (go (>! c (try
- (show "+")
- (let [x (wget)]
- (show ".")
- x)
- (catch Exception e
- ;; (str (.getMessage e))
- e)))))
- (deref p)))
- hello-world.core> (def x (time (snag-quotes 512)))
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.+.+.+.+.+.+.+.+.+.\
- +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+\
- .+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.\
- +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+\
- .+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.\
- +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+\
- .+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+..++.+.+.+.+.+.+.+.+.+.+.+.\
- +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+\
- .+.+.+.+.+.+.+.+.+.+.+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