jarohen / chord

A library designed to bridge the gap between the triad of CLJ/CLJS, web-sockets and core.async.
439 stars 40 forks source link

Example suggestion #12

Open noprompt opened 10 years ago

noprompt commented 10 years ago

It would be great if there were a minimal working example using chord with http-kit. The current example uses a lot of tools from several libraries, which is fine, but makes it difficult to understand at a basic level how to use this library. I'd be happy to send you a pull request of such an example but I'm having difficulty hooking it up. :wink:

dxlr8r commented 9 years ago

Would also be great if the example included an example of broadcasting through websocket to all clients

jarohen commented 9 years ago

Hi Simen - I'm pretty sure I've got an example of that kicking around somewhere - will see what I can find.

James

camelpunch commented 9 years ago

I've managed to do the broadcasting by having the server hold a reference to a mult and tapping with a dropping buffer for each new web socket channel. I'm unsure how to avoid leaking channels. I have regular updates sent from the server, so how do I clean up when a client leaves? The dropping buffer was a workaround to avoid holding up the mult.

camelpunch commented 9 years ago

Any luck finding that example @james-henderson ? I'm running into trouble using mults to distribute to clients. When I hit refresh in a client's browser, it seems to hang on to the tap (never untapped) and therefore holds the mult up indefinitely. There must be a better way I'm missing! Dropping-buffer just seems to lose important events.

Code here: https://github.com/pivotal-cf-experimental/diegotaskscheduler/blob/master/src/diegoscheduler/web.clj#L46

And here: https://github.com/pivotal-cf-experimental/diegotaskscheduler/blob/master/src/diegoscheduler/core.cljs#L73

jarohen commented 9 years ago

I couldn't find it, I'm afraid - I've moved companies since so it is probably in an old proprietary codebase :( Will take a look at your code snippets when I get a moment :)

James

camelpunch commented 9 years ago

Alright no worries. You may find I switched to another popular library ;)

On Wednesday, July 1, 2015, James Henderson notifications@github.com wrote:

I couldn't find it, I'm afraid - I've moved companies since so it is probably in an old proprietary codebase :( Will take a look at your code snippets when I get a mo!

James

— Reply to this email directly or view it on GitHub https://github.com/james-henderson/chord/issues/12#issuecomment-117583133 .

jarohen commented 9 years ago

Strewth that was quick. Sorry.

James

jarohen commented 9 years ago

@dxlr8r @camelpunch I've updated the example app to be a 'multiplayer chat' app - have a look here for the handler code.

Let me know what you think :)

camelpunch commented 9 years ago

Looks good. What's the thing I'm likely to be missing if, say, dead clients cause future ones to be unresponsive? As an aside, switching to Sente removed the problem, but then Sente does all sorts of reconnecting magic and wraps all sends in a function.

jarohen commented 9 years ago

As a guess, I'd say probably the call to untap - if you don't untap from a mult, then every time you send a message to the mult, it waits for all tapped channels to take the message before accepting the next message.