Hello Per,

thats very cool! Many thanks! Completely solves my problem. (As far as
I can see :-)

I'm not sure whether I completely understand the implications of the
nondeterminism you described; will think about it. You say "When each
promise can only be written by a single writer.." - I assume you mean
this as "Even if ..". Or am I on a wrong track?

Background: What I (still) try to do is to implement a blocking lazy
list. I'm not sure whether that should be used in the end, but while
experimenting with it, I want to print these lists, or, rather, a
state of such beast at a certain moment - and so the printer has to
stop at the current end of the list, and not block.

Thanks again, and kind regards,

alux



On 17 Apr., 16:46, Per Vognsen <per.vogn...@gmail.com> wrote:
> Not currently. I added the capability to some code I posted last month
> for fixing print-method for promises so they aren't auto-dereferenced
> when undelivered:
>
> (defn promise?
>   [p]
>   (isa? (type p) ::Promise))
>
> (defn promise-delivered?
>   [p]
>   (zero? (.getCount (:d p))))
>
> (defmethod print-method ::Promise
>   [writer p]
>   ((get-method print-method clojure.lang.IDeref) writer p))
>
> (defn promise
>   "Alpha - subject to change.
>   Returns a promise object that can be read with deref/@, and set,
>   once only, with deliver. Calls to deref/@ prior to delivery will
>   block. All subsequent derefs will return the same delivered value
>   without blocking."
>   []
>   (Promise (java.util.concurrent.CountDownLatch. 1) (atom nil)))
>
> But there are good reasons for why you might want to discourage this
> kind of checking in user code. When each promise can only be written
> by a single writer (i.e. there is not a race among several potential
> writers to first deliver the promise) then the input-output behavior
> of readers is deterministic only if such checking is disallowed. Under
> such conditions it doesn't matter if the readers try to dereference
> the promise before or after it is ultimately delivered by the writer.
> If readers can check the status of the promise, then you can get races
> between readers and the writer.
>
> -Per
>
>
>
> On Sat, Apr 17, 2010 at 7:00 PM, alux <alu...@googlemail.com> wrote:
> > Hi,
>
> > is there any nonblocking way I kind find out whether a promise has
> > been delivered?
>
> > Thanky you, alux
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > 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 post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to