raquo/Airstream

Consider keep-alive mechanisms to extend ownership duration

raquo opened this issue · 0 comments

raquo commented

Observable completion (#23) issue talks about killing subscriptions from the stream / producer side, usually to terminate the subscription early, such as the take / takeWhile operator (#33).

On the other hand, sometimes we actually want to extend the duration of the subscription for longer than the owner would normally allow. For example, in Laminar, element owners kill their subscriptions on unmount. So if you make an Ajax request and unmount the component before the response comes in, and nothing else listens to the response, the response will be ignored. Usually this is desired, but if the response observer has a side effect that you want to run regardless of the element's mount status, that side effect won't run.

To mitigate this we could mark this observer with something like keepAlive(maxEvents = 1, timeoutMs = 30000), meaning that any subscription created from it will not terminate immediately but will remain active for a maximum of one incombing event or a maximum of 30 seconds after the owner killed it, whichever comes first.

However, I'm not 100% sure if this is a good idea, because I think maybe the real solution is to use an observer owned by a global owner rather than by an element in such cases. Currently it's not really an option because the global owner would then accumulate many subscriptions from now-unmounted components over time, but maybe if we implement observable completion, we would be able to solve this (e.g. an ajax response stream would complete after emitting the result and any subscriptions listening to it would be killed since no new updates are expected).

Just some thoughts to get this out of my head.