user3743222 user3743222 - 5 months ago 22
Javascript Question

rxjs observables lifecycle : detecting a completed observable

Is there a way to know if an

Rx.Observable
has completed AFTER the fact, i.e. after
onCompleted
call on the subscribers? This would be similar to the
has_next
method for iterators. I could not find anything in the doc (or elsewhere) on that subject.

For a cold observable, the question would not make so much sense, as one can resubscribe at will, and the observable will be started anew. For a time-limited hot observable, one could imagine the edge case of being passed a reference to that hot observable, and subscribing for its values, never receiving anything and not even knowing that nothing will ever be received.

Answer

Here is the answer I got from another channel (quoted below).

The "usual" channels of creating a hot observable, such as creating a subject or using .publish() will "replay" the terminal message (i.e., onError or onCompleted), but there is no such guarantee in general. I would argue though that any hot sequence that did not have this terminal message replay violates the contract of an observable, and appropriate bugs should be filed.

Comments