puniverse / pulsar

Fibers, Channels and Actors for Clojure
http://docs.paralleluniverse.co/pulsar/
Other
911 stars 53 forks source link

pulsar/promise doesn't mimic clojure.core/promise #35

Closed dehubbed closed 9 years ago

dehubbed commented 9 years ago

Pulsar's promises are different from clojure.core's promises:

clojure.core's promises can be delivered to multiple times. so you can e.g. create a promise once (def p (promise)) and repeatedly call e.g. (deliver p 42). only the first call will set the value to 42, subsequent calls with the same or different value have no effect whereas pulsar's promises throw an exception. however on clojure.core the return value is different. the first call to deliver will return the promise itself, the same way pulsar's promises do. subsequent calls return nil.

I don't know whether pulsar's promises are supposed to be an exact drop-in replacement for clojure.core's promises, but if they are to be, then there might be code out there that relies on the above behavior that needs to be respected.

I know my code relies on the multiple-delivery ability. it sort of makes 'deliver' idempotent, an important quality in functional programming. the different return values are not only not significant to me but seem to counter immutability principles, however there might be code out there that relies on them.

pron commented 9 years ago

You are correct. As pulsar's promises should be drop-in replacements, subsequent calls to deliver should return nil (and have no effect), rather than throw an exception.

This will be fixed in the upcoming release.