core-async

Ovi Stoica 2025-03-05T09:02:59.783539Z

Maybe it’s just me, but this is the 2nd time I got burned thinking flow/inject respects order. Could we add a N.B.: inject does not guarantee order. Use ::flow/in-ports and a channel for that ?

2025-04-08T17:14:20.344699Z

All messages sent in a single inject call are made in order (it’s a doseq of >!!). No set of unawaited independent inject calls to different target coords could ever be in an order since each proc is always async relative to the others. But since inject returns a future you can ensure order by waiting for it before proceeding. Not sure how much more control you could want.

❤️ 1
Ovi Stoica 2025-03-05T09:04:47.669149Z

P.S. I know the inject function specifically states “asynchronously”, but I still fell for the mental trap

Alex Miller (Clojure team) 2025-03-05T13:27:21.432129Z

Order of what? I don’t understand

2025-03-05T13:30:28.352819Z

I guess he means if you do :

(do
  (flow/inject graph [:pid :nums-in] 1)
  (flow/inject graph [:pid :nums-in] 2)
  (flow/inject graph [:pid :nums-in] 3))
there is no guarantee that they will be received by :pid transform in that order

2025-03-05T13:34:49.391599Z

Which makes sense from the doc string saying Asynchronously but I guess people can misuse inject with code like (doseq [m msgs] (flow/inject ... m)) to push a bunch of messages into a graph and be confused with the result

Ovi Stoica 2025-03-05T13:51:38.988219Z

Yes. This is exactly what I mean. Sorry if it wasn't clear

phronmophobic 2025-03-05T17:28:56.841279Z

So even injections to the same [pid in-id] may be processed out of order?

Ovi Stoica 2025-03-05T19:18:04.498519Z

Yes. Each injection is put on a thread pool to be executed

Alex Miller (Clojure team) 2025-03-05T19:41:29.193199Z

I don’t know, that’s what “asynchronously” means?

2025-03-05T19:45:18.667209Z

maybe adding to the doc string a warning like "Since inject is async it shouldn't be used to inject a sequence of messages if their order matters, use flow/in-ports instead"?

cormacc 2025-03-14T13:16:20.121099Z

Maybe it's just me, but wouldn't flow/infect be an invaluable edition to any API? I don't really care what it does -- maybe make a server explode somewhere?