drapanjanas / pneumatic-tubes

WebSocket based transport of events between re-frame app and server
Eclipse Public License 1.0
58 stars 7 forks source link

Issues with sierra component integration #6

Open cjsauer opened 6 years ago

cjsauer commented 6 years ago

Hello,

First, thanks for this library. It's an awesome accomplishment.

I'm having some issues with wrapping tubes into a Sierra component (https://github.com/stuartsierra/component)

Mainly, from reading the code, it doesn't seem like support for (tubes/create! t), followed by (tubes/destroy! t), followed by another call to (tubes/create! t) is a supported operation. I'm noticing that the tube is still marked as :destroyed true even after I re-create it.

What is your suggestion for stopping and then starting a tube? Thanks!

drapanjanas commented 6 years ago

Hi, thanks for the report! I think you should be able to do that what you described. I do not use it like that in my app so I did not notice this problem before. Now I think problem might be somewhere here: https://github.com/drapanjanas/pneumatic-tubes/blob/master/src/cljs/pneumatic_tubes/core.cljs#L66 But I do not remember why I mark instances as destroyed and do not just remove them. I will give some thoughts about it and will fix this.

cjsauer commented 6 years ago

@drapanjanas could potentially be that the websocket's on-close event is asynchronous? It looks like there might be some cleanup code that runs in there, but I'm not sure.

Thanks for taking a look.

drapanjanas commented 6 years ago

@cjsauer yes I think this happens because of async onclose and onopen. Also because of the design issue. One way to fix this is to make tubes/create always return a new instance which can be used and destroyed independently. New code would look smth like this:

(def tube (tubes/create "ws://localhost:9090/ws" on-recv))
(dispatch tube [:my-event])
(tubes/destroy tube))

Not sure about old code, but might still be working.