rxjs-grpc icon indicating copy to clipboard operation
rxjs-grpc copied to clipboard

Dispose the stream if last subscriber terminates.

Open CihanSari opened this issue 6 years ago • 3 comments

In our workflow server is streaming until nobody is listening to. We don't get this information with the current observable. I had to fix this issue in a very similar fashion to this pull request at work. I have tried to isolate the necessary change to address the issue. I did not test the changes, especially because I have updated the rxjs requirement at work, and this meant a complete different interface. I hope this patch delivers the "no more subscribers" information to stream source.

CihanSari avatar Jun 15 '18 16:06 CihanSari

Hi!

Thanks for the finding! What does the finally operator help in this case? Can't we just return a call to cancel as unsubscribe function from the Observable factory function?

kondi avatar Jul 18 '18 13:07 kondi

Hi kondi!

Yes, that would be a solution. My old PR had the issue with canceling the call prematurely on first subscriber's unsubscription. I have merged the changes that I made for work and updated the PR. I had to clean A LOT OF code, and I couldn't test this version if it works, yet. However, I hope it gives you the idea.

Main decision to make is whether or not to replay the stream on consecutive subscribers to the shared observable.

CihanSari avatar Jul 18 '18 14:07 CihanSari

This solves only half the problem, as our server still keeps publishing without any care on the call status.

CihanSari avatar Jul 18 '18 20:07 CihanSari