This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-31
Channels
- # announcements (1)
- # aws (4)
- # babashka (40)
- # beginners (89)
- # calva (13)
- # cider (3)
- # clj-kondo (36)
- # cljdoc (16)
- # clojure (74)
- # clojure-boston (1)
- # clojure-dev (7)
- # clojure-europe (30)
- # clojure-new-zealand (1)
- # clojure-nl (17)
- # clojure-uk (5)
- # clojurescript (16)
- # core-async (9)
- # cursive (16)
- # datahike (3)
- # datalog (6)
- # datascript (7)
- # datomic (15)
- # emacs (38)
- # events (2)
- # figwheel-main (3)
- # fulcro (6)
- # google-cloud (18)
- # graalvm (6)
- # gratitude (1)
- # honeysql (1)
- # introduce-yourself (1)
- # jobs (1)
- # leiningen (5)
- # lsp (6)
- # malli (11)
- # meander (2)
- # off-topic (4)
- # re-frame (6)
- # reitit (8)
- # releases (2)
- # remote-jobs (3)
- # reveal (4)
- # shadow-cljs (200)
- # sql (8)
- # tools-deps (16)
I'm cross posting this question from #macchiato because i'm guessing it might be a core async misunerstanding i have more then something related to the node http server handler interaction Why would a macchiato server handler that consumes a promise inside a go block like this
(fn [request respond] (go (respond (<p! (some-core-aysnc-channel request)))))
result in an error about the stream write happening after end? I'm unsure what respond is doing, noly that it should be passed a hashmap with the response schema (body, status, etc...). I assume <p! is asynchoronous so it will block tell it gets the result. I'm not manully calling node server "end" or "write" here.
full stack trace is from my project and not the example code above, but the idea should be the same:
Error [ERR_STREAM_WRITE_AFTER_END] [ERR_STREAM_WRITE_AFTER_END]: write after end
at new NodeError (node:internal/errors:329:5)
at write_ (node:_http_outgoing:751:11)
at ServerResponse.write (node:_http_outgoing:710:15)
at /home/drewverlee/archmedx/kyber/server/dev/out/cljs-runtime/macchiato/http.cljs:110:5
at /home/drewverlee/archmedx/kyber/server/dev/out/cljs-runtime/macchiato/http.cljs:106:10
at respond_SINGLEQUOTE_ (/home/drewverlee/archmedx/kyber/server/dev/out/cljs-runtime/reitit/ring.cljc:119:43)
at respond__$1 (/home/drewverlee/archmedx/kyber/server/dev/out/cljs-runtime/macchiato/middleware/restful_format.cljs:110:24)
at switch__45133__auto__ (<eval>:75:27)
at <eval>:212:29
at Function.server$core$state_machine__45134__auto____1 [as cljs$core$IFn$_invoke$arity$1] (<eval>:234:4)
Note the go block correctly returns the results if run outside the handler context.if I'm reading correctly, most web servers assume that when your handler returns, that means it can write and close the response stream
unless you eg. return a channel or stream (which it would then use to fulfill the request)
so i need to get the result from the channel and .then
call the handler? that doesn't make any sense when i say it out loud, so i'm guessing no.
https://github.com/macchiato-framework/macchiato-core/blob/master/src/macchiato/http.cljs#L47-L97 couldn't leave it be, looks like this protocol function is called, and will raise an error if you don't return a type that satisfies the protocol
Thanks. Yea, i was worried that was likely the case. I was trying to understand if i could get around that somehow. If i deliver the promise in the handler shouldn't it have to block tell it resolves and becomes a value? ill figure it out, might have to build up my understanding a bit though. I was hoping to just be able to toss things in.