Catch exception from async process in Clojure? -
assume i'm sending email, asynchronously, , want program continue execution. far, i've been doing future
s, unfortunately, when email fails send, no exception raised.
i understand dereferencing future raise executionexception
, derefing defeat point.
is there better way "fire , go", without losing exception information?
i'd go agents this, using handler functions handle exceptions thrown agent actions:
(agent initial-state :error-handler handler-fn)
see (doc agent)
, (doc set-error-handler!)
, (doc set-error-mode!)
details. initial-state
here might nil
, or perhaps structure holding logging data.
to make convenient, you'd want have email
function usable send
(send-off
, send-via
):
(defn email [agent-state message] ...)
if main thread needs notified amiss, need pay attention communications on channel. (java queues 1 possibility, channels of core.async another.) handler function can push messages on channel.
Comments
Post a Comment