Fork me on GitHub

Would a websocket stream be a case to implement the clojure.core.async/Mult protocol? so that you can call tap on it to put incoming messages on a channel? Or is it probably better to just have the websocket provide an output channel for the user to make their own mult?

Jan K17:11:18

If you want a mult you don't need to implement protocols, just use the mult function to make one and put websocket messages into its channel. When you have multiple consumers, typically you'd have a central mult they can tap into, or you can use pub/sub for topic-based dispatch.

Jan K17:11:46

Can't give specific advice on where to put the mult without more context.


Yeah, I was using a mult already in this way. I just wasn't sure if making my websocket client itself a Mult, as a small shortcut, is an intended use of that protocol. I guess I'm just wondering what kind of situations might that protocol be extended, or is it always a bad idea? In my usage of websocket I do almost always want a mult. But I suppose most websocket client implementations expose just attaching a single handler for received messages, so that would map more cleanly to a single channel for received messages, as a base. But then maybe I could have a MultWebsocketConnection that could just be async/tap ed directly? Just thinking out loud here 🙂

Jan K17:11:54

I think the protocol should be considered a core.async implementation detail, not something to depend on. Just put the messages on a channel and make a mult on top.


Gotcha. I guess I just assumed since a lot of the async protocols are explicitly in an impl namespace, that maybe Mult being in the core namespace might be a hint that it should be used, but I probably read too much into this.