We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library version: 1.1.0
I've read https://uber.github.io/AutoDispose/ and looked, looked at Javadoc and https://github.com/uber/AutoDispose/blob/455ec23037d6e1af234d5fda9cd571c490d1b306/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java but it's still unclear I hope someone can shed some light on how I can achieve my goal: dispose the disposables when a specific event happens (user logs out
I have this custom LifecycleScopeProvider
class AuthenticationScopeProvider : LifecycleScopeProvider<AuthenticationEvent> { private val relay: BehaviorRelay<AuthenticationEvent> = BehaviorRelay.createDefault( AuthenticationEvent.PRE_AUTHENTICATED ) private val function : CorrespondingEventsFunction<AuthenticationEvent> by lazy { CorrespondingEventsFunction<AuthenticationEvent> { event -> when (event) { AuthenticationEvent.PRE_AUTHENTICATED, AuthenticationEvent.AUTHENTICATED -> AuthenticationEvent.LOGGED_OUT AuthenticationEvent.LOGGED_OUT -> throw LifecycleEndedException() } } } override fun lifecycle(): Observable<AuthenticationEvent> { return relay.hide() } override fun correspondingEvents(): CorrespondingEventsFunction<AuthenticationEvent> { return function } override fun peekLifecycle(): AuthenticationEvent? { return relay.value } /** * Call this when the user is authenticated with the CMB backend. */ fun becomeAuthenticated() { if (relay.value != AuthenticationEvent.AUTHENTICATED) { relay.accept(AuthenticationEvent.AUTHENTICATED) } } /** * Call this when a logout has started. */ fun becomeUnAuthenticated() { if (relay.value != AuthenticationEvent.LOGGED_OUT) { relay.accept(AuthenticationEvent.LOGGED_OUT) } }
But I'm not sure whether the disposal is actually happening Both this test
@Test fun `test dispose`() { val provider = AuthenticationScopeProvider() val obs = Single.fromCallable { Thread.sleep(2000L) return@fromCallable "something" }.subscribeOn(Schedulers.io()) val proxy = obs .`as`(AutoDispose.autoDisposable(provider)) val disposable = proxy.subscribe() provider.becomeUnAuthenticated(); Assert.assertTrue(disposable.isDisposed) }
and this
@Test(expected = LifecycleEndedException::class) fun `test dispose`() { val provider = AuthenticationScopeProvider() val obs = Single.fromCallable { Thread.sleep(2000L) return@fromCallable "something" }.subscribeOn(Schedulers.io()) val proxy = obs .`as`(AutoDispose.autoDisposable(provider)) val disposable = proxy.subscribe() provider.becomeUnAuthenticated(); }
fails
When I explicitly call provider.requestScope().subscribe(observer), the 2nd test passes
fun becomeUnAuthenticated() { if (relay.value != AuthenticationEvent.LOGGED_OUT) { relay.accept(AuthenticationEvent.LOGGED_OUT) } requestScope().subscribe(object : CompletableObserver { override fun onSubscribe(d: Disposable) { // no-op } override fun onComplete() { println("completed") // never triggered } override fun onError(e: Throwable) { e.printStackTrace() } }) }
However, the onComplete() is never called for the observer What am I missing?
onComplete()
The text was updated successfully, but these errors were encountered:
Please use the discussions section for questions, this is the issue tracker
Sorry, something went wrong.
No branches or pull requests
Library version: 1.1.0
I've read https://uber.github.io/AutoDispose/ and looked, looked at Javadoc and https://github.com/uber/AutoDispose/blob/455ec23037d6e1af234d5fda9cd571c490d1b306/autodispose/src/test/java/autodispose2/TestScopeProviderTest.java but it's still unclear
I hope someone can shed some light on how I can achieve my goal: dispose the disposables when a specific event happens (user logs out
I have this custom LifecycleScopeProvider
But I'm not sure whether the disposal is actually happening
Both this test
and this
fails
When I explicitly call provider.requestScope().subscribe(observer), the 2nd test passes
However, the
onComplete()
is never called for the observerWhat am I missing?
The text was updated successfully, but these errors were encountered: