Fork me on GitHub
#core-async
<
2017-04-17
>
lmergen07:04:30

what would be the idiomatic approach to block the current thread until a certain message is received from a core.async channel ? i would be err’ing towards a semaphore-like approach with a promise/future, but i was wondering whether there is a proper core.async facility for this…

mpenet08:04:00

Well, <!!

mpenet08:04:58

Or a promise + take! that delivers the value + deref on promise, which is almost the source of <!!

dergutemoritz10:04:11

@lmergen By "a certain message" you mean other messages may arrive before the one you are waiting for?

lmergen12:04:59

other messages may arrive

lmergen12:04:12

for context, i’m using the kinsky kafka library, which has a control channel that emits errors, or, an eof message in case the connection was closed

lmergen12:04:41

when my system shuts down, it can take a while before its entire buffer is flushed

lmergen12:04:52

more exceptions may be generated

lmergen12:04:59

so i need to wait for that specific eof message

lmergen12:04:44

so my current solution involves a poller go-loop that loops until the eof arrives, and then fulfills a promise

dergutemoritz13:04:46

Sounds like a good solution to me. You could alternatively pipe the control channel into another channel with a corresponding filter transducer and wait for that via <!! instead of derefing a promise. But I wouldn't say that's strictly more idiomatic...

dergutemoritz13:04:53

Actually, you don't even need the promise, just <!! on the channel returned by your go-loop

dergutemoritz13:04:05

(that's referring to your current solution)

lmergen13:04:23

yeah, that piping to another channel is what i also considered — multiplexing the control channel into several different channels, each with its own purpose, but i figured that was overkill and a simple cond block seems much simpler and more clear in its intent

lmergen13:04:59

that <!! is a good idea btw, thanks for that