I have a another stupid question:
How is this a race-condition / a source of problem given that:
* all I want to do is to read, I'm not writing / modifying
In particular, the sole goal of this read is to show a counter saying
"there are XYZ people ahead of you in line."
It seems that to have a race conditions, one needs to :
(1) thread-1 reads x
(2) thread-2 modifies x
(3) thread-1 writes some state depending on old value of x
On Sat, Jan 11, 2014 at 5:47 PM, Brandon Bloom <[email protected]>wrote:
> Any API that lets you peek at the "state" of a channel is a surefire
> source of race conditions. So no, public API-wise, there isn't any way to
> do what you want. In theory, you can peek at the internals using reflection
> to get that information, but don't do that!
>
> Instead, you can simply *count* yourself. Stick an extra go-loop on either
> end that swaps an atom with inc or dec.
>
> On Saturday, January 11, 2014 12:19:51 PM UTC-5, t x wrote:
>>
>> Hi,
>>
>> I have a clojure.core.async.chan
>>
>> Is there a way to figure out the # of elements currently queued on the
>> channel? (preferably in O(1) time)
>>
>> I don't want to actually take any item off the channel, I just want a
>> progress bar, something like "there are 20 transactions ahead of you in
>> life to be processed"
>>
>> 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.