src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java
void add(CacheSubscription<T> consumer) {
        for (;;) {
            CacheSubscription<T>[] current = subscribers.get();
            if (current == TERMINATED) {
                return;
            }
            int n = current.length;

            @SuppressWarnings("unchecked")
            CacheSubscription<T>[] next = new CacheSubscription[n + 1];
            System.arraycopy(current, 0, next, 0, n);
            next[n] = consumer;

            if (subscribers.compareAndSet(current, next)) {
                return;
            }
        }
    }
void add(CacheSubscription<T> consumer) {
        for (;;) {
            CacheSubscription<T>[] current = subscribers.get();
            if (current == TERMINATED) {
                return;
            }
            int n = current.length;

            @SuppressWarnings("unchecked")
            CacheSubscription<T>[] next = new CacheSubscription[n + 1];
            System.arraycopy(current, 0, next, 0, n);
            next[n] = consumer;

            if (subscribers.compareAndSet(current, next)) {
                return;
            }
        }
    }
void add ( CacheSubscription < T > consumer ) { for ( ; ; ) { CacheSubscription < T > [ ] current = subscribers . get ( ) ; if ( current == TERMINATED ) { return ; } int n = current . length ; @ SuppressWarnings ( "unchecked" ) CacheSubscription < T > [ ] next = new CacheSubscription [ n + 1 ] ; System . arraycopy ( current , 0 , next , 0 , n ) ; next [ n ] = consumer ; if ( subscribers . compareAndSet ( current , next ) ) { return ; } } }
Atomically adds the consumer to the {@link #subscribers} copy-on-write array
if the source has not yet terminated.
@param consumer the consumer to add
Atomically adds the consumer to the {