core-async

2020-11-27T16:34:57.264600Z

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 K 2020-11-27T17:35:18.264800Z

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 K 2020-11-27T17:43:46.265Z

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

2020-11-27T17:52:09.265200Z

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 K 2020-11-27T17:54:54.265500Z

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.

2020-11-27T17:57:19.265800Z

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.