Clojure

Add a way to test/detect promise objects

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I'd like a predicate to determine whether an object is a (promise). Currently promises are implemented as a reify of IFn and IDeref, meaning there is no meaningful superclass to test for. It seems to me the simplest solution would be to create an IPromise interface extending IDeref; then (defn promise? [x] (instance? IPromise x)) is a simple solution. Even an empty "tagging" interface for IPromise would do, but it might also be nice to add a delivered? predicate for promises so that it's possible to test whether they're delivered without blocking or catching the "multiple deliver" exception; that would make the IPromise interface more meaningful as well.

This is fairly simple stuff, so I'll start plugging away at a patch and hope nobody objects.

Activity

Hide
Alan Malloy added a comment -

Um, just noticed http://dev.clojure.org/jira/browse/CLJ-680 but I don't know how to close this issue as a duplicate of that one. The only thing his patch doesn't have that I'd like is:

(defn promise? [x] (instance? IPromiseImpl x))
(defn has-value? [^IPromiseImpl x] (.hasValue x))

Show
Alan Malloy added a comment - Um, just noticed http://dev.clojure.org/jira/browse/CLJ-680 but I don't know how to close this issue as a duplicate of that one. The only thing his patch doesn't have that I'd like is: (defn promise? [x] (instance? IPromiseImpl x)) (defn has-value? [^IPromiseImpl x] (.hasValue x))
Hide
Chas Emerick added a comment -

Closed per request from Alan Malloy.

Show
Chas Emerick added a comment - Closed per request from Alan Malloy.
Chas Emerick made changes -
Field Original Value New Value
Status Open [ 1 ] Closed [ 6 ]
Resolution Declined [ 2 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: