This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-06
Channels
- # beginners (95)
- # boot (3)
- # cider (13)
- # cljs-dev (9)
- # cljsjs (1)
- # cljsrn (35)
- # clojure (78)
- # clojure-dev (5)
- # clojure-italy (6)
- # clojure-nl (9)
- # clojure-russia (13)
- # clojure-spec (1)
- # clojure-uk (74)
- # clojurescript (59)
- # community-development (6)
- # core-async (41)
- # css (110)
- # data-science (2)
- # datomic (22)
- # defnpodcast (1)
- # devcards (1)
- # docs (1)
- # editors (6)
- # emacs (51)
- # figwheel (1)
- # fulcro (66)
- # jobs (1)
- # jobs-discuss (75)
- # lumo (51)
- # mount (2)
- # off-topic (33)
- # pedestal (24)
- # proton (3)
- # re-frame (29)
- # reagent (92)
- # reitit (16)
- # shadow-cljs (16)
- # spacemacs (4)
- # specter (6)
- # vim (6)
- # yada (7)
@mtnygard Does this suffice? https://gist.github.com/pithyless/51897363f5b6171a6d8e6368c60ab085
@pithyless Thank you, this is excellent. I will look into it later today.
@pithyless I could be wrong, but don’t you just want to return the channel returned from the go
? not provide an explicit extra channel?
e.g.,
(def do-work-async
{:name :do-work-async
:enter (fn [ctx]
(let [ch (async/chan)]
(async/go
(async/>! ch
(if (:async-error ctx)
(assert nil "Async error")
(assoc ctx :async :ok))))
ch))})
should be
(def do-work-async
{:name :do-work-async
:enter (fn [ctx]
(async/go
(if (:async-error ctx)
(assert nil "Async error")
(assoc ctx :async :ok))))})
I haven’t tested and edited the code in slack so parens are probably wrongfrom the pedestal reference guide: http://pedestal.io/reference/interceptors#_interceptor_return_values
(def third-party-auth
{:name ::third-party-auth
:enter (fn [context]
(if (:session context)
context
(go
(assoc context :auth-response (call-auth-system context))))})
they implicitly return a channel because the (go ..)
returns a channel@dadair in this case, having the async/go
return would be sufficient; but it makes no difference - error is the same
@pithyless There could be another difference. The assert
is going to throw an exception that will be silently swallowed by the inner go
. Nothing at all is going to come out of the channel if that happens.
But now that I look at it... I'm not sure how the assert would get caught outside any go block. I will have to take a fresh look at the Pedestal source to understand.
@mtnygard @dadair so without the explicit channel, just returning an implicit async/go
channel, we see something like this:
Async error...
Exception in thread "async-dispatch-5" java.lang.AssertionError: Assert failed: Async error
nil
[OK] Handling error.
clojure.lang.ExceptionInfo: Async Interceptor closed Context Channel before delivering a Context
at clojure.core$ex_info.invokeStatic (core.clj:4739)
clojure.core$ex_info.invoke (core.clj:4739)
If you want the exception to be processed with Pedestal's error handling, I guess you need to catch Throwable
and attach it to the context map before putting the context map into the channel.
Do you mean, the way I wrote about it yesterday? https://clojurians.slack.com/archives/C0K65B20P/p1522937421000780