Sunday, 15 July 2018

Determine when Subject has no subscribers

I want to create a broadcast system using PublishSubject, a background task will poll some endpoint and broadcast the result periodically using this Subject. I would like to start the polling when the first subscriber subscribes to the Subject, and stop the polling when there are no more subscribers. If a new subscriber subscribes, polling should resume.

The only function I see that is somewhat related is hasObservers() but it doesn't quite fit my needs, I would like to have callbacks for subscription and unsubscription - on the former I would start polling if not stated, and on the latter I would stop polling if there are no more subscribers; how could this be achieved?



from Determine when Subject has no subscribers

No comments:

Post a Comment