David Smith
2015-03-24 16:19:29 UTC
deferred/on-realized seems to return different things depending on the
situation, in the case of an unrealized deferred it simply returns true.
Is there a reason for this?
In order to create wrapper functions that do various things on success and
failure I currently need to put the deferred in a let binding. If
on-realized returned the deferred I would not need to do this.
(defn wrap-stats
[f]
(fn [arg]
(let [r (f arg)]
(d/on-realized r
(fn [_] (println "send some success stats!"))
(fn [_] (println "send some error stats!")))
r)))
(defn wrap-logging
[f]
(fn [arg]
(let [r (f arg)]
(d/on-realized r
(fn [x] (println "success2!" x))
(fn [e] (println "failure2!" e)))
r)))
Could be replaced by:
(defn wrap-stats
[f]
(fn [arg]
(d/on-realized (f arg)
(fn [_] (println "send some success stats!"))
(fn [_] (println "send some error stats!")))))
(defn wrap-logging
[f]
(fn [arg]
(d/on-realized (f arg)
(fn [x] (println "success2!" x))
(fn [e] (println "failure2!" e)))))
situation, in the case of an unrealized deferred it simply returns true.
Is there a reason for this?
In order to create wrapper functions that do various things on success and
failure I currently need to put the deferred in a let binding. If
on-realized returned the deferred I would not need to do this.
(defn wrap-stats
[f]
(fn [arg]
(let [r (f arg)]
(d/on-realized r
(fn [_] (println "send some success stats!"))
(fn [_] (println "send some error stats!")))
r)))
(defn wrap-logging
[f]
(fn [arg]
(let [r (f arg)]
(d/on-realized r
(fn [x] (println "success2!" x))
(fn [e] (println "failure2!" e)))
r)))
Could be replaced by:
(defn wrap-stats
[f]
(fn [arg]
(d/on-realized (f arg)
(fn [_] (println "send some success stats!"))
(fn [_] (println "send some error stats!")))))
(defn wrap-logging
[f]
(fn [arg]
(d/on-realized (f arg)
(fn [x] (println "success2!" x))
(fn [e] (println "failure2!" e)))))
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.