-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1215ba3
commit 86a158d
Showing
4 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3759,6 +3759,21 @@ | |
([opts stream] | ||
(. clojure.lang.LispReader (read stream opts)))) | ||
|
||
(defn read+string | ||
"Like read, and taking the same args. stream must be a LineNumberingPushbackReader. | ||
Returns a vector containing the object read and the (whitespace-trimmed) string read." | ||
{:added "1.10"} | ||
([] (read+string *out*)) | ||
([^clojure.lang.LineNumberingPushbackReader stream & args] | ||
(try | ||
(.captureString stream) | ||
(let [o (apply read stream args) | ||
s (.trim (.getString stream))] | ||
[o s]) | ||
(catch Throwable ex | ||
(.getString stream) | ||
(throw ex))))) | ||
|
||
(defn read-line | ||
"Reads the next line from stream that is the current value of *in* ." | ||
{:added "1.0" | ||
|
@@ -7766,3 +7781,43 @@ | |
"Return true if x is a java.net.URI" | ||
{:added "1.9"} | ||
[x] (instance? java.net.URI x)) | ||
|
||
(defonce ^:private tapset (atom #{})) | ||
(defonce ^:private ^java.util.concurrent.ArrayBlockingQueue tapq (java.util.concurrent.ArrayBlockingQueue. 1024)) | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
puredanger
Member
|
||
(defn add-tap | ||
"adds f, a fn of one argument, to the tap set. This function will be called with anything sent via tap>. | ||
This function may (briefly) block (e.g. for streams), and will never impede calls to tap>, | ||
but blocking indefinitely may cause tap values to be dropped. | ||
Remember f in order to remove-tap" | ||
{:added "1.10"} | ||
[f] | ||
(swap! tapset conj f) | ||
nil) | ||
|
||
(defn remove-tap | ||
"remove f from the tap set the tap set." | ||
{:added "1.10"} | ||
[f] | ||
(swap! tapset disj f) | ||
nil) | ||
|
||
(defn tap> | ||
"sends x to any taps. Will not block. Returns true if there was room in the queue, | ||
false if not (dropped)." | ||
{:added "1.10"} | ||
[x] | ||
(.offer tapq x)) | ||
|
||
(defonce ^:private tap-loop | ||
(doto (Thread. | ||
#(let [x (.take tapq) | ||
taps @tapset] | ||
(doseq [tap taps] | ||
(try | ||
(tap x) | ||
(catch Throwable ex))) | ||
(recur)) | ||
"clojure.core/tap-loop") | ||
(.setDaemon true) | ||
(.start))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Wouldn't creating a
clojure.core.tap
ns be reasonable approach?That gives you opportunity to add a ns docstring describing what taps are, and why would one use them.
Sometimes one can only see the leaves (individual docstrings) but not the forest :)
Other concerns also apply:
clojure.core.tap <TAB>
(the least thing I would want is to engage in discussion with you / make you spend time explaining. You either agree or not, generally we all trust Clojure core to make sound designs)