src/main/java/io/reactivex/internal/disposables/ArrayCompositeDisposable.java
public boolean setResource(int index, Disposable resource) {
        for (;;) {
            Disposable o = get(index);
            if (o == DisposableHelper.DISPOSED) {
                resource.dispose();
                return false;
            }
            if (compareAndSet(index, o, resource)) {
                if (o != null) {
                    o.dispose();
                }
                return true;
            }
        }
    }
public boolean setResource(int index, Disposable resource) {
        for (;;) {
            Disposable o = get(index);
            if (o == DisposableHelper.DISPOSED) {
                resource.dispose();
                return false;
            }
            if (compareAndSet(index, o, resource)) {
                if (o != null) {
                    o.dispose();
                }
                return true;
            }
        }
    }
public boolean setResource ( int index , Disposable resource ) { for ( ; ; ) { Disposable o = get ( index ) ; if ( o == DisposableHelper . DISPOSED ) { resource . dispose ( ) ; return false ; } if ( compareAndSet ( index , o , resource ) ) { if ( o != null ) { o . dispose ( ) ; } return true ; } } }
Sets the resource at the specified index and disposes the old resource.
@param index the index of the resource to set
@param resource the new resource
@return true if the resource has ben set, false if the composite has been disposed
Sets the resource at the specified index and disposes the old resource .