Search code examples
javarx-javarx-android

What it means for Disposable.dispose() to be idempotent?


RxJava documentation for Disposable.dispose states

Dispose the resource, the operation should be idempotent.

And according to the Wikipedia definition of Idempotence

Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.

Does it mean calling dispose() method on same Disposable multiple times will not have any additional effects? Will it dispose related resources only once?

That raises another question - what is the need for isDisposed() method then? Isn't it for checking if a disposable is disposed before disposing it again?


Solution

  • You answered your own question.

    Does it mean calling dispose() method on same Disposable multiple times will not have any additional effects? Will it dispose related resources only once?

    This is correct. Regarding the isDisposed() method, its purpose is probably checking whether a resource has been disposed before you begin using it.