clj-commons / manifold

A compatibility layer for event-driven abstractions
1.02k stars 106 forks source link

Allowing return of deferred values from catch? #24

Closed bts closed 9 years ago

bts commented 9 years ago

Hey Zach,

What are your thoughts on allowing the return of deferred values from d/catch? Currently deferreds from d/catch aren't "flattened" as they are with d/chain and friends. e.g.:

user=> (d/catch (d/error-deferred (Exception.)) (fn [e] (d/success-deferred :delayed-recovery)))
<< << :delayed-recovery >> >>

I find myself wanting to do this so that I can catch errors while in a d/loop, and d/recur once I've recovered (asynchronously) from the error (e.g., performing a "cooldown" sleep before recurring.)

Thanks, Brian

ztellman commented 9 years ago

I think flattening out values from catch via unwrap seems like a good idea, I think that's just an oversight on my part. Pull request welcome, or I can take care of it myself.

bts commented 9 years ago

I just saw your response a few minutes ago and started to take a look. You beat me to it -- thanks for implementing this!