Discussion:
would be nice if on-realized returned deferred
David Smith
2015-03-24 16:19:29 UTC
Permalink
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)))))
--
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.
Zach Tellman
2015-03-24 16:55:43 UTC
Permalink
Okay, sure. Want to open an issue on Github?
Post by David Smith
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)))
(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
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.
David Smith
2015-04-08 18:01:17 UTC
Permalink
Sorry it took a while but I
created https://github.com/ztellman/manifold/pull/33, what do you think?
Post by Zach Tellman
Okay, sure. Want to open an issue on Github?
Post by David Smith
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)))
(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
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.
Loading...