Skip to content

Unused unsubscribe method on CompletableUseCase #32

Open
@gh-23378

Description

@gh-23378

It looks like we're just creating an empty disposable in this class and disposing of it in unsubscribe without ever changing its value. In the SingleUseCase class, we pass an observer into the execute method and capture a reference to the subscription by subscribing inside of thhat method. I would have expected the same to happen in this class, or if the idea is that we subscribe manually from our presenter, shouldn't we also unsubscribe manually and remove this unsubscribe method altogether?

abstract class CompletableUseCase<in Params> protected constructor(
        private val threadExecutor: ThreadExecutor,
        private val postExecutionThread: PostExecutionThread) {
    // Here we initialize subscription as an empty disposable
    private val subscription = Disposables.empty()
    protected abstract fun buildUseCaseObservable(params: Params): Completable

    // I would have expected an observer to be passed into execute so that we can
    // subscribe in this method and obtain a reference to the subscription 
    fun execute(params: Params): Completable {
        return this.buildUseCaseObservable(params)
                .subscribeOn(Schedulers.from(threadExecutor))
                .observeOn(postExecutionThread.scheduler)
    }

    // Now we unsubscribe from our empty disposable
    fun unsubscribe() {
        if (!subscription.isDisposed) {
            subscription.dispose()
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions