Jozef:
(let []
(def c (async/chan 10))
(def cf (async/filter> #(if (even? %) %
(assert false))
c))
(async/>!! cf 2)
(try
(async/>!! cf 1)
(catch Exception e
(println "caught exception")))
)
I believe filter> causes the exception to be thrown in a _different_
thread, not the thread that does the >!!
On Wed, Jan 22, 2014 at 2:14 AM, Jozef Wagner <[email protected]>wrote:
> use filter>
>
> user=> (def c (chan 10))
> #'user/c
> user=> (def cf (filter> #(if (even? %) % (throw
> (IllegalArgumentException.))) c))
> #'user/cf
> user=> (>!! cf 2)
> nil
> user=> (>!! cf 1)
> IllegalArgumentException user/fn--4294
> (form-init9067455327434905636.clj:1)
> user=> (>!! cf 4)
> nil
> user=> (<!! cf)
> 2
> user=> (<!! cf)
> 4
>
> JW
>
>
> On Wed, Jan 22, 2014 at 9:43 AM, t x <[email protected]> wrote:
>
>> With apologies for spamming:
>>
>> in case anyone else wanted a solution to this problem:
>>
>> I believe the right layer is to wrap at the Channel layer, rather than
>> the Buffer layer: for example:
>>
>>
>> (ns test
>> (:require
>> #+clj [clojure.core.async.impl.protocols :as impl]
>> #+cljs [cljs.core.async.impl.protocols :as impl]
>> #+clj [clojure.core.async.impl.channels :as channels]
>> #+cljs [cljs.core.async.impl.channels :as channels]
>> #+clj [clojure.core.async :as async]
>> #+cljs [cljs.core.async :as async]))
>>
>> (do
>>
>> (deftype CheckedChannel [chan check]
>> impl/WritePort (put! [this val handler]
>> (check val)
>> (impl/put! chan val handler))
>> impl/ReadPort (take! [this handler]
>> (impl/take! chan handler))
>> impl/Channel (close! [this]
>> (impl/close! chan)))
>>
>>
>> (defn cchan [n check]
>> (CheckedChannel. (async/chan n) check))
>>
>>
>> (def oc (cchan 100 #(assert (even? %))))
>>
>> (println "Line 1")
>> (async/alts!! [[oc 2]] :default :chan-full)
>> (println "Line 2")
>> (async/alts!! [[oc 3]] :default :chan-full)
>> (println "Line 3")
>> (async/alts!! [[oc 3]] :default :chan-full)
>> (println "Line 4")
>>
>> )
>>
>>
>>
>> On Wed, Jan 22, 2014 at 12:02 AM, t x <[email protected]> wrote:
>>
>>> Consider the following attempt:
>>>
>>> for some reason, after the assertion fails, the main repl thread seems
>>> to lock up
>>>
>>> Line 1
>>> Line 2 // after this, no more is printed
>>>
>>>
>>> Question: what is causing the problem -- and how do I fix it?
>>>
>>> Thanks!
>>>
>>> === code ===
>>>
>>> (ns test
>>> (:require
>>> #+clj [clojure.core.async.impl.protocols :as impl]
>>> #+cljs [cljs.core.async.impl.protocols :as impl]
>>> #+clj [clojure.core.async.impl.channels :as channels]
>>> #+cljs [cljs.core.async.impl.channels :as channels]
>>> #+clj [clojure.core.async :as async]
>>> #+cljs [cljs.core.async :as async]))
>>>
>>> (do
>>>
>>> (deftype CheckedBuffer [buf check]
>>> impl/Buffer
>>> (full? [this] (impl/full? buf))
>>> (remove! [this] (impl/remove! buf))
>>> (add! [this itm]
>>> (check itm)
>>> (impl/add! buf itm)))
>>>
>>>
>>> (defn cchan [n check]
>>> (channels/chan (CheckedBuffer. (async/buffer n) check)))
>>>
>>>
>>> (def oc (cchan 100 #(assert (even? %))))
>>>
>>> (println "Line 1")
>>> (async/alts!! [[oc 2]] :default :chan-full)
>>> (println "Line 2")
>>> (async/alts!! [[oc 3]] :default :chan-full)
>>> (println "Line 3")
>>> (async/alts!! [[oc 3]] :default :chan-full)
>>> (println "Line 4")
>>>
>>> )
>>>
>>>
>>>
>>> On Tue, Jan 21, 2014 at 11:46 PM, Kelker Ryan <[email protected]>wrote:
>>>
>>>> Can't you just test the value before placing a value in a channel?
>>>>
>>>> 22.01.2014, 16:27, "t x" <[email protected]>:
>>>>
>>>> Hi,
>>>>
>>>>
>>>> ## Question:
>>>>
>>>> For a channel, is it possible to put a pre-condition of sorts on a
>>>> channel?
>>>>
>>>> For example:
>>>>
>>>> (let [chan (async/chan 100)]
>>>> (set-pre-condition! chan even?)
>>>> (put! chan 1) ;; exception thrown
>>>> (>!! chan 3) ;; exception thrown
>>>> )
>>>>
>>>> ## Asides
>>>>
>>>> It's important that I want the exception to be thrown at the time of
>>>> put, NOT at the time of take via <! or <!!.
>>>> Thanks!
>>>>
>>>>
>>>> --
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to [email protected]
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>> --
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to [email protected]
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.