# WhileSubscribed(5000)

DevFeed: [WhileSubscribed(5000)](<https://devfeed.tech/articles/whilesubscribed-5000-25635.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/whilesubscribed5000>)

Author: Pierre-Yves Ricau

Published: 2022-08-30T23:01:56Z

Content type: article

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [leakcanary](<https://devfeed.tech/topics/leakcanary.md>), [now-in-android](<https://devfeed.tech/topics/now-in-android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-apps](<https://devfeed.tech/tags/android-apps.md>), [android-engineer](<https://devfeed.tech/tags/android-engineer.md>), [app](<https://devfeed.tech/tags/app.md>), [block](<https://devfeed.tech/tags/block.md>), [compose](<https://devfeed.tech/tags/compose.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [delay](<https://devfeed.tech/tags/delay.md>), [flow](<https://devfeed.tech/tags/flow.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [gabor-varadi](<https://devfeed.tech/tags/gabor-varadi.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [leaks](<https://devfeed.tech/tags/leaks.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [now-in-android](<https://devfeed.tech/tags/now-in-android.md>), [operators](<https://devfeed.tech/tags/operators.md>), [scope](<https://devfeed.tech/tags/scope.md>), [stream](<https://devfeed.tech/tags/stream.md>), [twitter](<https://devfeed.tech/tags/twitter.md>)

## AI overview

The 5-second WhileSubscribed timeout keeps an upstream flow active briefly after its last collector disappears, which can avoid restarting it during an activity configuration change. Without the delay, rotation can drop the subscription count to zero, stop sharing, then restart the upstream flow on resume; the cached state value is reused. The author objects to treating this delay as a default for every ViewModel flow. Eagerly starting sharing avoids that restart, but keeps the upstream flow active for the ViewModel's lifetime, typically tied to an Activity or Fragment. The excerpt does not describe further limitations or alternatives.

## Source excerpt

👋 Hi, this is P.Y., I work as an Android Engineer at Block. I know nothing about Compose so please let me know if I messed up on Twitter! I've been hacking on a new LeakCanary standalone app to visua