Input: Subscribes to a Maybe and provides callbacks to handle the items it emits and any error notification it issues . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code subscribe } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Disposable subscribe ( Consumer < ? super T > onSuccess , Consumer < ? super Throwable > onError ) { return subscribe ( onSuccess , onError , Functions . EMPTY_ACTION ) ; }


Input: Returns a Maybe that emits the items emitted by the source Maybe or the items of an alternate MaybeSource if the current Maybe is empty . <p > <img width = 640 height = 445 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / switchifempty . m . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code switchIfEmpty } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Maybe < T > switchIfEmpty ( MaybeSource < ? extends T > other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeSwitchIfEmpty < T > ( this , other ) ) ; }


Input: Returns a Single that emits the items emitted by the source Maybe or the item of an alternate SingleSource if the current Maybe is empty . <p > <img width = 640 height = 445 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / switchifempty . m . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Single < T > switchIfEmpty ( SingleSource < ? extends T > other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeSwitchIfEmptySingle < T > ( this , other ) ) ; }


Input: Returns a Maybe that emits the items emitted by the source Maybe until a second MaybeSource emits an item . <p > <img width = 640 height = 380 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / takeUntil . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code takeUntil } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > Maybe < T > takeUntil ( MaybeSource < U > other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeTakeUntilMaybe < T , U > ( this , other ) ) ; }


Input: Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted item . If the next item isn t emitted within the specified timeout duration starting from its predecessor the resulting Maybe terminates and notifies MaybeObservers of a { @code TimeoutException } . <p > <img width = 640 height = 305 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / timeout . 1 . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > This version of { @code timeout } operates by default on the { @code computation } { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . COMPUTATION ) public final Maybe < T > timeout ( long timeout , TimeUnit timeUnit ) { return timeout ( timeout , timeUnit , Schedulers . computation ( ) ) ; }


Input: Returns a Maybe that mirrors the source Maybe but applies a timeout policy for each emitted item where this policy is governed on a specified Scheduler . If the next item isn t emitted within the specified timeout duration starting from its predecessor the resulting Maybe terminates and notifies MaybeObservers of a { @code TimeoutException } . <p > <img width = 640 height = 305 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / timeout . 1s . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > You specify which { @link Scheduler } this operator will use . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Maybe < T > timeout ( long timeout , TimeUnit timeUnit , Scheduler scheduler ) { return timeout ( timer ( timeout , timeUnit , scheduler ) ) ; }


Input: If the current { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > Maybe < T > timeout ( MaybeSource < U > timeoutIndicator ) { ObjectHelper . requireNonNull ( timeoutIndicator , "timeoutIndicator is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeTimeoutMaybe < T , U > ( this , timeoutIndicator , null ) ) ; }


Input: If the current { [CODESPLIT] @ BackpressureSupport ( BackpressureKind . UNBOUNDED_IN ) @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > Maybe < T > timeout ( Publisher < U > timeoutIndicator ) { ObjectHelper . requireNonNull ( timeoutIndicator , "timeoutIndicator is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeTimeoutPublisher < T , U > ( this , timeoutIndicator , null ) ) ; }


Input: Returns a Maybe which makes sure when a MaybeObserver disposes the Disposable that call is propagated up on the specified scheduler . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Maybe < T > unsubscribeOn ( final Scheduler scheduler ) { ObjectHelper . requireNonNull ( scheduler , "scheduler is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeUnsubscribeOn < T > ( this , scheduler ) ) ; }


Input: Creates a OperatorPublish instance to publish values of the given source observable . [CODESPLIT] public static < T > ConnectableFlowable < T > create ( Flowable < T > source , final int bufferSize ) { // the current connection to source needs to be shared between the operator and its onSubscribe call final AtomicReference < PublishSubscriber < T > > curr = new AtomicReference < PublishSubscriber < T > > ( ) ; Publisher < T > onSubscribe = new FlowablePublisher < T > ( curr , bufferSize ) ; return RxJavaPlugins . onAssembly ( new FlowablePublish < T > ( onSubscribe , source , curr , bufferSize ) ) ; }


Input: Creates a { [CODESPLIT] public static < T > SingleObserver < T > create ( Observer < ? super T > downstream ) { return new SingleToObservableObserver < T > ( downstream ) ; }


Input: Verifies if the object is not null and returns it or throws a NullPointerException with the given message . [CODESPLIT] public static < T > T requireNonNull ( T object , String message ) { if ( object == null ) { throw new NullPointerException ( message ) ; } return object ; }


Input: Returns a BiPredicate that compares its parameters via Objects . equals () . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) public static < T > BiPredicate < T , T > equalsPredicate ( ) { return ( BiPredicate < T , T > ) EQUALS ; }


Input: Emits the given exception if possible or adds it to the given error container to be emitted by a concurrent onNext if one is running . Undeliverable exceptions are sent to the RxJavaPlugins . onError . [CODESPLIT] public static void onError ( Subscriber < ? > subscriber , Throwable ex , AtomicInteger wip , AtomicThrowable error ) { if ( error . addThrowable ( ex ) ) { if ( wip . getAndIncrement ( ) == 0 ) { subscriber . onError ( error . terminate ( ) ) ; } } else { RxJavaPlugins . onError ( ex ) ; } }


Input: Emits an onComplete signal or an onError signal with the given error or indicates the concurrently running onNext should do that . [CODESPLIT] public static void onComplete ( Subscriber < ? > subscriber , AtomicInteger wip , AtomicThrowable error ) { if ( wip . getAndIncrement ( ) == 0 ) { Throwable ex = error . terminate ( ) ; if ( ex != null ) { subscriber . onError ( ex ) ; } else { subscriber . onComplete ( ) ; } } }


Input: Emits the given exception if possible or adds it to the given error container to be emitted by a concurrent onNext if one is running . Undeliverable exceptions are sent to the RxJavaPlugins . onError . [CODESPLIT] public static void onError ( Observer < ? > observer , Throwable ex , AtomicInteger wip , AtomicThrowable error ) { if ( error . addThrowable ( ex ) ) { if ( wip . getAndIncrement ( ) == 0 ) { observer . onError ( error . terminate ( ) ) ; } } else { RxJavaPlugins . onError ( ex ) ; } }


Input: Emits an onComplete signal or an onError signal with the given error or indicates the concurrently running onNext should do that . [CODESPLIT] public static void onComplete ( Observer < ? > observer , AtomicInteger wip , AtomicThrowable error ) { if ( wip . getAndIncrement ( ) == 0 ) { Throwable ex = error . terminate ( ) ; if ( ex != null ) { observer . onError ( ex ) ; } else { observer . onComplete ( ) ; } } }


Input: Returns an identity function that simply returns its argument . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) public static < T > Function < T , T > identity ( ) { return ( Function < T , T > ) IDENTITY ; }


Input: Returns a Callable that returns the given value . [CODESPLIT] public static < T > Callable < T > justCallable ( T value ) { return new JustValue < Object , T > ( value ) ; }


Input: Returns a Function that ignores its parameter and returns the given value . [CODESPLIT] public static < T , U > Function < T , U > justFunction ( U value ) { return new JustValue < T , U > ( value ) ; }


Input: Returns a function that cast the incoming values via a Class object . [CODESPLIT] public static < T , U > Function < T , U > castFunction ( Class < U > target ) { return new CastToClass < T , U > ( target ) ; }


Input: Special handling for printing out a { @code CompositeException } . Loops through all inner exceptions and prints them out . [CODESPLIT] private void printStackTrace ( PrintStreamOrWriter s ) { StringBuilder b = new StringBuilder ( 128 ) ; b . append ( this ) . append ( ' ' ) ; for ( StackTraceElement myStackElement : getStackTrace ( ) ) { b . append ( "\tat " ) . append ( myStackElement ) . append ( ' ' ) ; } int i = 1 ; for ( Throwable ex : exceptions ) { b . append ( "  ComposedException " ) . append ( i ) . append ( " :\n" ) ; appendStackTrace ( b , ex , "\t" ) ; i ++ ; } s . println ( b . toString ( ) ) ; }


Input: / * private [CODESPLIT] Throwable getRootCause ( Throwable e ) { Throwable root = e . getCause ( ) ; if ( root == null || e == root ) { return e ; } while ( true ) { Throwable cause = root . getCause ( ) ; if ( cause == null || cause == root ) { return root ; } root = cause ; } }


Input: Creates an UnicastSubject with an internal buffer capacity hint 16 . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > UnicastSubject < T > create ( ) { return new UnicastSubject < T > ( bufferSize ( ) , true ) ; }


Input: Creates an UnicastSubject with the given internal buffer capacity hint . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > UnicastSubject < T > create ( int capacityHint ) { return new UnicastSubject < T > ( capacityHint , true ) ; }


Input: Creates an UnicastSubject with the given internal buffer capacity hint and a callback for the case when the single Subscriber cancels its subscription . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > UnicastSubject < T > create ( int capacityHint , Runnable onTerminate ) { return new UnicastSubject < T > ( capacityHint , onTerminate , true ) ; }


Input: Creates an UnicastSubject with an internal buffer capacity hint 16 and given delay error flag . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > UnicastSubject < T > create ( boolean delayError ) { return new UnicastSubject < T > ( bufferSize ( ) , delayError ) ; }


Input: Tries to emit the item to all currently subscribed Subscribers if all of them has requested some value returns false otherwise . <p > This method should be called in a sequential manner just like the onXXX methods of the PublishProcessor . <p > Calling with null will terminate the PublishProcessor and a NullPointerException is signalled to the Subscribers . <p > History : 2 . 0 . 8 - experimental [CODESPLIT] public boolean offer ( T t ) { if ( t == null ) { onError ( new NullPointerException ( "onNext called with null. Null values are generally not allowed in 2.x operators and sources." ) ) ; return true ; } PublishSubscription < T > [ ] array = subscribers . get ( ) ; for ( PublishSubscription < T > s : array ) { if ( s . isFull ( ) ) { return false ; } } for ( PublishSubscription < T > s : array ) { s . onNext ( t ) ; } return true ; }


Input: final : fixed protocol steps to support fuseable and non - fuseable upstream [CODESPLIT] @ SuppressWarnings ( "unchecked" ) @ Override public final void onSubscribe ( Disposable d ) { if ( DisposableHelper . validate ( this . upstream , d ) ) { this . upstream = d ; if ( d instanceof QueueDisposable ) { this . qd = ( QueueDisposable < T > ) d ; } if ( beforeDownstream ( ) ) { downstream . onSubscribe ( this ) ; afterDownstream ( ) ; } } }


Input: ----------------------------------- [CODESPLIT] @ Override public void onError ( Throwable t ) { if ( done ) { RxJavaPlugins . onError ( t ) ; return ; } done = true ; downstream . onError ( t ) ; }


Input: Rethrows the throwable if it is a fatal exception or calls { [CODESPLIT] protected final void fail ( Throwable t ) { Exceptions . throwIfFatal ( t ) ; upstream . dispose ( ) ; onError ( t ) ; }


Input: Calls the upstream s QueueDisposable . requestFusion with the mode and saves the established mode in { [CODESPLIT] protected final int transitiveBoundaryFusion ( int mode ) { QueueDisposable < T > qd = this . qd ; if ( qd != null ) { if ( ( mode & BOUNDARY ) == 0 ) { int m = qd . requestFusion ( mode ) ; if ( m != NONE ) { sourceMode = m ; } return m ; } } return NONE ; }


Input: Block until the latch is counted down and return the error received or null if no error happened . [CODESPLIT] public Throwable blockingGetError ( ) { if ( getCount ( ) != 0 ) { try { BlockingHelper . verifyNonBlocking ( ) ; await ( ) ; } catch ( InterruptedException ex ) { dispose ( ) ; return ex ; } } return error ; }


Input: Block until the latch is counted down and return the error received or when the wait is interrupted or times out null otherwise . [CODESPLIT] public Throwable blockingGetError ( long timeout , TimeUnit unit ) { if ( getCount ( ) != 0 ) { try { BlockingHelper . verifyNonBlocking ( ) ; if ( ! await ( timeout , unit ) ) { dispose ( ) ; throw ExceptionHelper . wrapOrThrow ( new TimeoutException ( timeoutMessage ( timeout , unit ) ) ) ; } } catch ( InterruptedException ex ) { dispose ( ) ; throw ExceptionHelper . wrapOrThrow ( ex ) ; } } return error ; }


Input: Block until the observer terminates and return true ; return false if the wait times out . [CODESPLIT] public boolean blockingAwait ( long timeout , TimeUnit unit ) { if ( getCount ( ) != 0 ) { try { BlockingHelper . verifyNonBlocking ( ) ; if ( ! await ( timeout , unit ) ) { dispose ( ) ; return false ; } } catch ( InterruptedException ex ) { dispose ( ) ; throw ExceptionHelper . wrapOrThrow ( ex ) ; } } Throwable ex = error ; if ( ex != null ) { throw ExceptionHelper . wrapOrThrow ( ex ) ; } return true ; }


Input: Creates an unbounded ReplayProcessor with the specified initial buffer capacity . <p > Use this method to avoid excessive array reallocation while the internal buffer grows to accommodate new items . For example if you know that the buffer will hold 32k items you can ask the { @code ReplayProcessor } to preallocate its internal array with a capacity to hold that many items . Once the items start to arrive the internal array won t need to grow creating less garbage and no overhead due to frequent array - copying . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > ReplayProcessor < T > create ( int capacityHint ) { return new ReplayProcessor < T > ( new UnboundedReplayBuffer < T > ( capacityHint ) ) ; }


Input: Creates a size - bounded ReplayProcessor . <p > In this setting the { @code ReplayProcessor } holds at most { @code size } items in its internal buffer and discards the oldest item . <p > When { @code Subscriber } s subscribe to a terminated { @code ReplayProcessor } they are guaranteed to see at most { @code size } { @code onNext } events followed by a termination event . <p > If a { @code Subscriber } subscribes while the { @code ReplayProcessor } is active it will observe all items in the buffer at that point in time and each item observed afterwards even if the buffer evicts items due to the size constraint in the mean time . In other words once a { @code Subscriber } subscribes it will receive items without gaps in the sequence . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > ReplayProcessor < T > createWithSize ( int maxSize ) { return new ReplayProcessor < T > ( new SizeBoundReplayBuffer < T > ( maxSize ) ) ; }


Input: / * test [CODESPLIT] static < T > ReplayProcessor < T > createUnbounded ( ) { return new ReplayProcessor < T > ( new SizeBoundReplayBuffer < T > ( Integer . MAX_VALUE ) ) ; }


Input: Creates a time - bounded ReplayProcessor . <p > In this setting the { @code ReplayProcessor } internally tags each observed item with a timestamp value supplied by the { @link Scheduler } and keeps only those whose age is less than the supplied time value converted to milliseconds . For example an item arrives at T = 0 and the max age is set to 5 ; at T&gt ; = 5 this first item is then evicted by any subsequent item or termination event leaving the buffer empty . <p > Once the processor is terminated { @code Subscriber } s subscribing to it will receive items that remained in the buffer after the terminal event regardless of their age . <p > If a { @code Subscriber } subscribes while the { @code ReplayProcessor } is active it will observe only those items from within the buffer that have an age less than the specified time and each item observed thereafter even if the buffer evicts items due to the time constraint in the mean time . In other words once a { @code Subscriber } subscribes it observes items without gaps in the sequence except for any outdated items at the beginning of the sequence . <p > Note that terminal notifications ( { @code onError } and { @code onComplete } ) trigger eviction as well . For example with a max age of 5 the first item is observed at T = 0 then an { @code onComplete } notification arrives at T = 10 . If a { @code Subscriber } subscribes at T = 11 it will find an empty { @code ReplayProcessor } with just an { @code onComplete } notification . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > ReplayProcessor < T > createWithTime ( long maxAge , TimeUnit unit , Scheduler scheduler ) { return new ReplayProcessor < T > ( new SizeAndTimeBoundReplayBuffer < T > ( Integer . MAX_VALUE , maxAge , unit , scheduler ) ) ; }


Input: final : fixed protocol steps to support fuseable and non - fuseable upstream [CODESPLIT] @ SuppressWarnings ( "unchecked" ) @ Override public final void onSubscribe ( Subscription s ) { if ( SubscriptionHelper . validate ( this . upstream , s ) ) { this . upstream = s ; if ( s instanceof QueueSubscription ) { this . qs = ( QueueSubscription < T > ) s ; } if ( beforeDownstream ( ) ) { downstream . onSubscribe ( this ) ; afterDownstream ( ) ; } } }


Input: Rethrows the throwable if it is a fatal exception or calls { [CODESPLIT] protected final void fail ( Throwable t ) { Exceptions . throwIfFatal ( t ) ; upstream . cancel ( ) ; onError ( t ) ; }


Input: Calls the upstream s QueueSubscription . requestFusion with the mode and saves the established mode in { [CODESPLIT] protected final int transitiveBoundaryFusion ( int mode ) { QueueSubscription < T > qs = this . qs ; if ( qs != null ) { if ( ( mode & BOUNDARY ) == 0 ) { int m = qs . requestFusion ( mode ) ; if ( m != NONE ) { sourceMode = m ; } return m ; } } return NONE ; }


Input: Creates a { @link BehaviorSubject } that emits the last item it observed and all subsequent items to each { @link Observer } that subscribes to it . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > BehaviorSubject < T > createDefault ( T defaultValue ) { return new BehaviorSubject < T > ( defaultValue ) ; }


Input: Returns a single value the Subject currently has or null if no such value exists . <p > The method is thread - safe . [CODESPLIT] @ Nullable public T getValue ( ) { Object o = value . get ( ) ; if ( NotificationLite . isComplete ( o ) || NotificationLite . isError ( o ) ) { return null ; } return NotificationLite . getValue ( o ) ; }


Input: Returns an Object array containing snapshot all values of the Subject . <p > The method is thread - safe . [CODESPLIT] @ Deprecated public Object [ ] getValues ( ) { @ SuppressWarnings ( "unchecked" ) T [ ] a = ( T [ ] ) EMPTY_ARRAY ; T [ ] b = getValues ( a ) ; if ( b == EMPTY_ARRAY ) { return new Object [ 0 ] ; } return b ; }


Input: Returns a typed array containing a snapshot of all values of the Subject . <p > The method follows the conventions of Collection . toArray by setting the array element after the last value to null ( if the capacity permits ) . <p > The method is thread - safe . [CODESPLIT] @ Deprecated @ SuppressWarnings ( "unchecked" ) public T [ ] getValues ( T [ ] array ) { Object o = value . get ( ) ; if ( o == null || NotificationLite . isComplete ( o ) || NotificationLite . isError ( o ) ) { if ( array . length != 0 ) { array [ 0 ] = null ; } return array ; } T v = NotificationLite . getValue ( o ) ; if ( array . length != 0 ) { array [ 0 ] = v ; if ( array . length != 1 ) { array [ 1 ] = null ; } } else { array = ( T [ ] ) Array . newInstance ( array . getClass ( ) . getComponentType ( ) , 1 ) ; array [ 0 ] = v ; } return array ; }


Input: Returns true if the subject has any value . <p > The method is thread - safe . [CODESPLIT] public boolean hasValue ( ) { Object o = value . get ( ) ; return o != null && ! NotificationLite . isComplete ( o ) && ! NotificationLite . isError ( o ) ; }


Input: Drain the queue but give up with an error if there aren t enough requests . [CODESPLIT] public static < T , U > void drainMaxLoop ( SimplePlainQueue < T > q , Subscriber < ? super U > a , boolean delayError , Disposable dispose , QueueDrain < T , U > qd ) { int missed = 1 ; for ( ; ; ) { for ( ; ; ) { boolean d = qd . done ( ) ; T v = q . poll ( ) ; boolean empty = v == null ; if ( checkTerminated ( d , empty , a , delayError , q , qd ) ) { if ( dispose != null ) { dispose . dispose ( ) ; } return ; } if ( empty ) { break ; } long r = qd . requested ( ) ; if ( r != 0L ) { if ( qd . accept ( a , v ) ) { if ( r != Long . MAX_VALUE ) { qd . produced ( 1 ) ; } } } else { q . clear ( ) ; if ( dispose != null ) { dispose . dispose ( ) ; } a . onError ( new MissingBackpressureException ( "Could not emit value due to lack of requests." ) ) ; return ; } } missed = qd . leave ( - missed ) ; if ( missed == 0 ) { break ; } } }


Input: Creates a queue : spsc - array if capacityHint is positive and spsc - linked - array if capacityHint is negative ; in both cases the capacity is the absolute value of prefetch . [CODESPLIT] public static < T > SimpleQueue < T > createQueue ( int capacityHint ) { if ( capacityHint < 0 ) { return new SpscLinkedArrayQueue < T > ( - capacityHint ) ; } return new SpscArrayQueue < T > ( capacityHint ) ; }


Input: Requests Long . MAX_VALUE if prefetch is negative or the exact amount if prefetch is positive . [CODESPLIT] public static void request ( Subscription s , int prefetch ) { s . request ( prefetch < 0 ? Long . MAX_VALUE : prefetch ) ; }


Input: Accumulates requests ( not validated ) and handles the completed mode draining of the queue based on the requests . [CODESPLIT] public static < T > boolean postCompleteRequest ( long n , Subscriber < ? super T > actual , Queue < T > queue , AtomicLong state , BooleanSupplier isCancelled ) { for ( ; ; ) { long r = state . get ( ) ; // extract the current request amount long r0 = r & REQUESTED_MASK ; // preserve COMPLETED_MASK and calculate new requested amount long u = ( r & COMPLETED_MASK ) | BackpressureHelper . addCap ( r0 , n ) ; if ( state . compareAndSet ( r , u ) ) { // (complete, 0) -> (complete, n) transition then replay if ( r == COMPLETED_MASK ) { postCompleteDrain ( n | COMPLETED_MASK , actual , queue , state , isCancelled ) ; return true ; } // (active, r) -> (active, r + n) transition then continue with requesting from upstream return false ; } } }


Input: Drains the queue based on the outstanding requests in post - completed mode ( only! ) . [CODESPLIT] static < T > boolean postCompleteDrain ( long n , Subscriber < ? super T > actual , Queue < T > queue , AtomicLong state , BooleanSupplier isCancelled ) { // TODO enable fast-path //        if (n == -1 || n == Long.MAX_VALUE) { //            for (;;) { //                if (isCancelled.getAsBoolean()) { //                    break; //                } // //                T v = queue.poll(); // //                if (v == null) { //                    actual.onComplete(); //                    break; //                } // //                actual.onNext(v); //            } // //            return true; //        } long e = n & COMPLETED_MASK ; for ( ; ; ) { while ( e != n ) { if ( isCancelled ( isCancelled ) ) { return true ; } T t = queue . poll ( ) ; if ( t == null ) { actual . onComplete ( ) ; return true ; } actual . onNext ( t ) ; e ++ ; } if ( isCancelled ( isCancelled ) ) { return true ; } if ( queue . isEmpty ( ) ) { actual . onComplete ( ) ; return true ; } n = state . get ( ) ; if ( n == e ) { n = state . addAndGet ( - ( e & REQUESTED_MASK ) ) ; if ( ( n & REQUESTED_MASK ) == 0L ) { return false ; } e = n & COMPLETED_MASK ; } } }


Input: Signals the completion of the main sequence and switches to post - completion replay mode . [CODESPLIT] public static < T > void postComplete ( Subscriber < ? super T > actual , Queue < T > queue , AtomicLong state , BooleanSupplier isCancelled ) { if ( queue . isEmpty ( ) ) { actual . onComplete ( ) ; return ; } if ( postCompleteDrain ( state . get ( ) , actual , queue , state , isCancelled ) ) { return ; } for ( ; ; ) { long r = state . get ( ) ; if ( ( r & COMPLETED_MASK ) != 0L ) { return ; } long u = r | COMPLETED_MASK ; // (active, r) -> (complete, r) transition if ( state . compareAndSet ( r , u ) ) { // if the requested amount was non-zero, drain the queue if ( r != 0L ) { postCompleteDrain ( u , actual , queue , state , isCancelled ) ; } return ; } } }


Input: Creates an unbounded replay subject . <p > The internal buffer is backed by an { @link ArrayList } and starts with an initial capacity of 16 . Once the number of items reaches this capacity it will grow as necessary ( usually by 50% ) . However as the number of items grows this causes frequent array reallocation and copying and may hurt performance and latency . This can be avoided with the { @link #create ( int ) } overload which takes an initial capacity parameter and can be tuned to reduce the array reallocation frequency as needed . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > ReplaySubject < T > create ( ) { return new ReplaySubject < T > ( new UnboundedReplayBuffer < T > ( 16 ) ) ; }


Input: Creates a size - bounded replay subject . <p > In this setting the { @code ReplaySubject } holds at most { @code size } items in its internal buffer and discards the oldest item . <p > When observers subscribe to a terminated { @code ReplaySubject } they are guaranteed to see at most { @code size } { @code onNext } events followed by a termination event . <p > If an observer subscribes while the { @code ReplaySubject } is active it will observe all items in the buffer at that point in time and each item observed afterwards even if the buffer evicts items due to the size constraint in the mean time . In other words once an Observer subscribes it will receive items without gaps in the sequence . [CODESPLIT] @ CheckReturnValue @ NonNull public static < T > ReplaySubject < T > createWithSize ( int maxSize ) { return new ReplaySubject < T > ( new SizeBoundReplayBuffer < T > ( maxSize ) ) ; }


Input: / * test [CODESPLIT] static < T > ReplaySubject < T > createUnbounded ( ) { return new ReplaySubject < T > ( new SizeBoundReplayBuffer < T > ( Integer . MAX_VALUE ) ) ; }


Input: Signals the given value and an onComplete if the downstream is ready to receive the final value . [CODESPLIT] protected final void complete ( R n ) { long p = produced ; if ( p != 0 ) { BackpressureHelper . produced ( this , p ) ; } for ( ; ; ) { long r = get ( ) ; if ( ( r & COMPLETE_MASK ) != 0 ) { onDrop ( n ) ; return ; } if ( ( r & REQUEST_MASK ) != 0 ) { lazySet ( COMPLETE_MASK + 1 ) ; downstream . onNext ( n ) ; downstream . onComplete ( ) ; return ; } value = n ; if ( compareAndSet ( 0 , COMPLETE_MASK ) ) { return ; } value = null ; } }


Input: Returns an Object array containing snapshot all values of this processor . <p > The method is thread - safe . [CODESPLIT] @ Deprecated public Object [ ] getValues ( ) { T v = getValue ( ) ; return v != null ? new Object [ ] { v } : new Object [ 0 ] ; }


Input: Returns a typed array containing a snapshot of all values of this processor . <p > The method follows the conventions of Collection . toArray by setting the array element after the last value to null ( if the capacity permits ) . <p > The method is thread - safe . [CODESPLIT] @ Deprecated public T [ ] getValues ( T [ ] array ) { T v = getValue ( ) ; if ( v == null ) { if ( array . length != 0 ) { array [ 0 ] = null ; } return array ; } if ( array . length == 0 ) { array = Arrays . copyOf ( array , 1 ) ; } array [ 0 ] = v ; if ( array . length != 1 ) { array [ 1 ] = null ; } return array ; }


Input: Returns the contained value if this notification is an onNext signal null otherwise . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) @ Nullable public T getValue ( ) { Object o = value ; if ( o != null && ! NotificationLite . isError ( o ) ) { return ( T ) value ; } return null ; }


Input: Returns the container Throwable error if this notification is an onError signal null otherwise . [CODESPLIT] @ Nullable public Throwable getError ( ) { Object o = value ; if ( NotificationLite . isError ( o ) ) { return NotificationLite . getError ( o ) ; } return null ; }


Input: Constructs an onNext notification containing the given value . [CODESPLIT] @ NonNull public static < T > Notification < T > createOnNext ( @ NonNull T value ) { ObjectHelper . requireNonNull ( value , "value is null" ) ; return new Notification < T > ( value ) ; }


Input: Constructs an onError notification containing the error . [CODESPLIT] @ NonNull public static < T > Notification < T > createOnError ( @ NonNull Throwable error ) { ObjectHelper . requireNonNull ( error , "error is null" ) ; return new Notification < T > ( NotificationLite . error ( error ) ) ; }


Input: Ensures that the upstream Disposable is null and returns true otherwise disposes the next Disposable and if the upstream is not the shared disposed instance reports a ProtocolViolationException due to multiple subscribe attempts . [CODESPLIT] public static boolean validate ( Disposable upstream , Disposable next , Class < ? > observer ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; if ( upstream != null ) { next . dispose ( ) ; if ( upstream != DisposableHelper . DISPOSED ) { reportDoubleSubscription ( observer ) ; } return false ; } return true ; }


Input: Atomically updates the target upstream AtomicReference from null to the non - null next Disposable otherwise disposes next and reports a ProtocolViolationException if the AtomicReference doesn t contain the shared disposed indicator . [CODESPLIT] public static boolean setOnce ( AtomicReference < Disposable > upstream , Disposable next , Class < ? > observer ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; if ( ! upstream . compareAndSet ( null , next ) ) { next . dispose ( ) ; if ( upstream . get ( ) != DisposableHelper . DISPOSED ) { reportDoubleSubscription ( observer ) ; } return false ; } return true ; }


Input: Ensures that the upstream Subscription is null and returns true otherwise cancels the next Subscription and if the upstream is not the shared cancelled instance reports a ProtocolViolationException due to multiple subscribe attempts . [CODESPLIT] public static boolean validate ( Subscription upstream , Subscription next , Class < ? > subscriber ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; if ( upstream != null ) { next . cancel ( ) ; if ( upstream != SubscriptionHelper . CANCELLED ) { reportDoubleSubscription ( subscriber ) ; } return false ; } return true ; }


Input: Atomically updates the target upstream AtomicReference from null to the non - null next Subscription otherwise cancels next and reports a ProtocolViolationException if the AtomicReference doesn t contain the shared cancelled indicator . [CODESPLIT] public static boolean setOnce ( AtomicReference < Subscription > upstream , Subscription next , Class < ? > subscriber ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; if ( ! upstream . compareAndSet ( null , next ) ) { next . cancel ( ) ; if ( upstream . get ( ) != SubscriptionHelper . CANCELLED ) { reportDoubleSubscription ( subscriber ) ; } return false ; } return true ; }


Input: Atomically adds the consumer to the { [CODESPLIT] 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 ; } } }


Input: Atomically removes the consumer from the { [CODESPLIT] @ SuppressWarnings ( "unchecked" ) void remove ( CacheSubscription < T > consumer ) { for ( ; ; ) { CacheSubscription < T > [ ] current = subscribers . get ( ) ; int n = current . length ; if ( n == 0 ) { return ; } int j = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( current [ i ] == consumer ) { j = i ; break ; } } if ( j < 0 ) { return ; } CacheSubscription < T > [ ] next ; if ( n == 1 ) { next = EMPTY ; } else { next = new CacheSubscription [ n - 1 ] ; System . arraycopy ( current , 0 , next , 0 , j ) ; System . arraycopy ( current , j + 1 , next , j , n - j - 1 ) ; } if ( subscribers . compareAndSet ( current , next ) ) { return ; } } }


Input: Replays the contents of this cache to the given consumer based on its current state and number of items requested by it . [CODESPLIT] void replay ( CacheSubscription < T > consumer ) { // make sure there is only one replay going on at a time if ( consumer . getAndIncrement ( ) != 0 ) { return ; } // see if there were more replay request in the meantime int missed = 1 ; // read out state into locals upfront to avoid being re-read due to volatile reads long index = consumer . index ; int offset = consumer . offset ; Node < T > node = consumer . node ; AtomicLong requested = consumer . requested ; Subscriber < ? super T > downstream = consumer . downstream ; int capacity = capacityHint ; for ( ; ; ) { // first see if the source has terminated, read order matters! boolean sourceDone = done ; // and if the number of items is the same as this consumer has received boolean empty = size == index ; // if the source is done and we have all items so far, terminate the consumer if ( sourceDone && empty ) { // release the node object to avoid leaks through retained consumers consumer . node = null ; // if error is not null then the source failed Throwable ex = error ; if ( ex != null ) { downstream . onError ( ex ) ; } else { downstream . onComplete ( ) ; } return ; } // there are still items not sent to the consumer if ( ! empty ) { // see how many items the consumer has requested in total so far long consumerRequested = requested . get ( ) ; // MIN_VALUE indicates a cancelled consumer, we stop replaying if ( consumerRequested == Long . MIN_VALUE ) { // release the node object to avoid leaks through retained consumers consumer . node = null ; return ; } // if the consumer has requested more and there is more, we will emit an item if ( consumerRequested != index ) { // if the offset in the current node has reached the node capacity if ( offset == capacity ) { // switch to the subsequent node node = node . next ; // reset the in-node offset offset = 0 ; } // emit the cached item downstream . onNext ( node . values [ offset ] ) ; // move the node offset forward offset ++ ; // move the total consumed item count forward index ++ ; // retry for the next item/terminal event if any continue ; } } // commit the changed references back consumer . index = index ; consumer . offset = offset ; consumer . node = node ; // release the changes and see if there were more replay request in the meantime missed = consumer . addAndGet ( - missed ) ; if ( missed == 0 ) { break ; } } }


Input: Adds two long values and caps the sum at Long . MAX_VALUE . [CODESPLIT] public static long addCap ( long a , long b ) { long u = a + b ; if ( u < 0L ) { return Long . MAX_VALUE ; } return u ; }


Input: Multiplies two long values and caps the product at Long . MAX_VALUE . [CODESPLIT] public static long multiplyCap ( long a , long b ) { long u = a * b ; if ( ( ( a | b ) >>> 31 ) != 0 ) { if ( u / a != b ) { return Long . MAX_VALUE ; } } return u ; }


Input: Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long . MAX_VALUE and returns the previous value . [CODESPLIT] public static long add ( AtomicLong requested , long n ) { for ( ; ; ) { long r = requested . get ( ) ; if ( r == Long . MAX_VALUE ) { return Long . MAX_VALUE ; } long u = addCap ( r , n ) ; if ( requested . compareAndSet ( r , u ) ) { return r ; } } }


Input: Atomically adds the positive value n to the requested value in the AtomicLong and caps the result at Long . MAX_VALUE and returns the previous value and considers Long . MIN_VALUE as a cancel indication ( no addition then ) . [CODESPLIT] public static long addCancel ( AtomicLong requested , long n ) { for ( ; ; ) { long r = requested . get ( ) ; if ( r == Long . MIN_VALUE ) { return Long . MIN_VALUE ; } if ( r == Long . MAX_VALUE ) { return Long . MAX_VALUE ; } long u = addCap ( r , n ) ; if ( requested . compareAndSet ( r , u ) ) { return r ; } } }


Input: Atomically subtract the given number ( positive not validated ) from the target field unless it contains Long . MAX_VALUE . [CODESPLIT] public static long produced ( AtomicLong requested , long n ) { for ( ; ; ) { long current = requested . get ( ) ; if ( current == Long . MAX_VALUE ) { return Long . MAX_VALUE ; } long update = current - n ; if ( update < 0L ) { RxJavaPlugins . onError ( new IllegalStateException ( "More produced than requested: " + update ) ) ; update = 0L ; } if ( requested . compareAndSet ( current , update ) ) { return update ; } } }


Input: Subscribes to the source and calls the Observer methods on the current thread . <p > [CODESPLIT] public static < T > void subscribe ( ObservableSource < ? extends T > o , Observer < ? super T > observer ) { final BlockingQueue < Object > queue = new LinkedBlockingQueue < Object > ( ) ; BlockingObserver < T > bs = new BlockingObserver < T > ( queue ) ; observer . onSubscribe ( bs ) ; o . subscribe ( bs ) ; for ( ; ; ) { if ( bs . isDisposed ( ) ) { break ; } Object v = queue . poll ( ) ; if ( v == null ) { try { v = queue . take ( ) ; } catch ( InterruptedException ex ) { bs . dispose ( ) ; observer . onError ( ex ) ; return ; } } if ( bs . isDisposed ( ) || o == BlockingObserver . TERMINATED || NotificationLite . acceptFull ( v , observer ) ) { break ; } } }


Input: Runs the source observable to a terminal event ignoring any values and rethrowing any exception . [CODESPLIT] public static < T > void subscribe ( ObservableSource < ? extends T > o ) { BlockingIgnoringReceiver callback = new BlockingIgnoringReceiver ( ) ; LambdaObserver < T > ls = new LambdaObserver < T > ( Functions . emptyConsumer ( ) , callback , callback , Functions . emptyConsumer ( ) ) ; o . subscribe ( ls ) ; BlockingHelper . awaitForComplete ( callback , ls ) ; Throwable e = callback . error ; if ( e != null ) { throw ExceptionHelper . wrapOrThrow ( e ) ; } }


Input: Subscribes to the source and calls the given actions on the current thread . [CODESPLIT] public static < T > void subscribe ( ObservableSource < ? extends T > o , final Consumer < ? super T > onNext , final Consumer < ? super Throwable > onError , final Action onComplete ) { ObjectHelper . requireNonNull ( onNext , "onNext is null" ) ; ObjectHelper . requireNonNull ( onError , "onError is null" ) ; ObjectHelper . requireNonNull ( onComplete , "onComplete is null" ) ; subscribe ( o , new LambdaObserver < T > ( onNext , onError , onComplete , Functions . emptyConsumer ( ) ) ) ; }


Input: Returns a Completable which completes only when all sources complete one after another . <p > <img width = 640 height = 283 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . concatArray . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable concatArray ( CompletableSource ... sources ) { ObjectHelper . requireNonNull ( sources , "sources is null" ) ; if ( sources . length == 0 ) { return complete ( ) ; } else if ( sources . length == 1 ) { return wrap ( sources [ 0 ] ) ; } return RxJavaPlugins . onAssembly ( new CompletableConcatArray ( sources ) ) ; }


Input: Returns a Completable which completes only when all sources complete one after another . <p > <img width = 640 height = 303 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . concat . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable concat ( Iterable < ? extends CompletableSource > sources ) { ObjectHelper . requireNonNull ( sources , "sources is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableConcatIterable ( sources ) ) ; }


Input: Returns a Completable which completes only when all sources complete one after another . <p > <img width = 640 height = 237 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . concat . p . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . FULL ) public static Completable concat ( Publisher < ? extends CompletableSource > sources ) { return concat ( sources , 2 ) ; }


Input: Returns a Completable which completes only when all sources complete one after another . <p > <img width = 640 height = 237 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . concat . pn . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . FULL ) public static Completable concat ( Publisher < ? extends CompletableSource > sources , int prefetch ) { ObjectHelper . requireNonNull ( sources , "sources is null" ) ; ObjectHelper . verifyPositive ( prefetch , "prefetch" ) ; return RxJavaPlugins . onAssembly ( new CompletableConcat ( sources , prefetch ) ) ; }


Input: Provides an API ( via a cold Completable ) that bridges the reactive world with the callback - style world . <p > <img width = 640 height = 442 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . create . png alt = > <p > Example : <pre > <code > Completable . create ( emitter - &gt ; { Callback listener = new Callback () { &#64 ; Override public void onEvent ( Event e ) { emitter . onComplete () ; } [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable create ( CompletableOnSubscribe source ) { ObjectHelper . requireNonNull ( source , "source is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableCreate ( source ) ) ; }


Input: Creates a Completable instance that emits the given Throwable exception to subscribers . <p > <img width = 640 height = 462 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . error . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable error ( final Throwable error ) { ObjectHelper . requireNonNull ( error , "error is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableError ( error ) ) ; }


Input: Returns a Completable instance that runs the given Action for each subscriber and emits either an unchecked exception or simply completes . <p > <img width = 640 height = 297 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . fromAction . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable fromAction ( final Action run ) { ObjectHelper . requireNonNull ( run , "run is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableFromAction ( run ) ) ; }


Input: Returns a Completable which when subscribed executes the callable function ignores its normal result and emits onError or onComplete only . <p > <img width = 640 height = 286 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . fromCallable . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable fromCallable ( final Callable < ? > callable ) { ObjectHelper . requireNonNull ( callable , "callable is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableFromCallable ( callable ) ) ; }


Input: Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion . <p > <img width = 640 height = 628 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . fromFuture . png alt = > <p > Note that if any of the observers to this Completable call dispose this Completable will cancel the future . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable fromFuture ( final Future < ? > future ) { ObjectHelper . requireNonNull ( future , "future is null" ) ; return fromAction ( Functions . futureAction ( future ) ) ; }


Input: Returns a Completable instance that when subscribed to subscribes to the { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static < T > Completable fromMaybe ( final MaybeSource < T > maybe ) { ObjectHelper . requireNonNull ( maybe , "maybe is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeIgnoreElementCompletable < T > ( maybe ) ) ; }


Input: Returns a Completable instance that runs the given Runnable for each subscriber and emits either its exception or simply completes . <p > <img width = 640 height = 297 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . fromRunnable . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable fromRunnable ( final Runnable run ) { ObjectHelper . requireNonNull ( run , "run is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableFromRunnable ( run ) ) ; }


Input: Returns a Completable instance that when subscribed to subscribes to the Single instance and emits a completion event if the single emits onSuccess or forwards any onError events . <p > <img width = 640 height = 356 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . fromSingle . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static < T > Completable fromSingle ( final SingleSource < T > single ) { ObjectHelper . requireNonNull ( single , "single is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableFromSingle < T > ( single ) ) ; }


Input: Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error . <p > <img width = 640 height = 270 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . mergeArray . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable mergeArray ( CompletableSource ... sources ) { ObjectHelper . requireNonNull ( sources , "sources is null" ) ; if ( sources . length == 0 ) { return complete ( ) ; } else if ( sources . length == 1 ) { return wrap ( sources [ 0 ] ) ; } return RxJavaPlugins . onAssembly ( new CompletableMergeArray ( sources ) ) ; }


Input: Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error . <p > <img width = 640 height = 311 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . merge . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable merge ( Iterable < ? extends CompletableSource > sources ) { ObjectHelper . requireNonNull ( sources , "sources is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableMergeIterable ( sources ) ) ; }


Input: Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error . <p > <img width = 640 height = 336 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . merge . p . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . UNBOUNDED_IN ) public static Completable merge ( Publisher < ? extends CompletableSource > sources ) { return merge0 ( sources , Integer . MAX_VALUE , false ) ; }


Input: Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source Completables complete or one of them emits an error . <p > <img width = 640 height = 269 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . merge . pn . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . FULL ) public static Completable merge ( Publisher < ? extends CompletableSource > sources , int maxConcurrency ) { return merge0 ( sources , maxConcurrency , false ) ; }


Input: Returns a Completable that subscribes to all Completables in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another . <p > <img width = 640 height = 466 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . mergeDelayError . p . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . UNBOUNDED_IN ) public static Completable mergeDelayError ( Publisher < ? extends CompletableSource > sources ) { return merge0 ( sources , Integer . MAX_VALUE , true ) ; }


Input: Returns a Completable that subscribes to a limited number of inner Completables at once in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another . <p > <img width = 640 height = 440 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . mergeDelayError . pn . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) @ BackpressureSupport ( BackpressureKind . FULL ) public static Completable mergeDelayError ( Publisher < ? extends CompletableSource > sources , int maxConcurrency ) { return merge0 ( sources , maxConcurrency , true ) ; }


Input: Returns a Completable that never calls onError or onComplete . <p > <img width = 640 height = 512 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . never . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable never ( ) { return RxJavaPlugins . onAssembly ( CompletableNever . INSTANCE ) ; }


Input: Returns a Completable instance that fires its onComplete event after the given delay elapsed . <p > <img width = 640 height = 413 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . timer . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . COMPUTATION ) public static Completable timer ( long delay , TimeUnit unit ) { return timer ( delay , unit , Schedulers . computation ( ) ) ; }


Input: Creates a NullPointerException instance and sets the given Throwable as its initial cause . [CODESPLIT] private static NullPointerException toNpe ( Throwable ex ) { NullPointerException npe = new NullPointerException ( "Actually not, but can't pass out an exception otherwise..." ) ; npe . initCause ( ex ) ; return npe ; }


Input: Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active . <p > <img width = 640 height = 388 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . using . png alt = > <p > This overload disposes eagerly before the terminal event is emitted . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public static < R > Completable using ( Callable < R > resourceSupplier , Function < ? super R , ? extends CompletableSource > completableFunction , Consumer < ? super R > disposer ) { return using ( resourceSupplier , completableFunction , disposer , true ) ; }


Input: Wraps the given CompletableSource into a Completable if not already Completable . <p > <img width = 640 height = 354 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . wrap . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public static Completable wrap ( CompletableSource source ) { ObjectHelper . requireNonNull ( source , "source is null" ) ; if ( source instanceof Completable ) { return RxJavaPlugins . onAssembly ( ( Completable ) source ) ; } return RxJavaPlugins . onAssembly ( new CompletableFromUnsafeSource ( source ) ) ; }


Input: Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first . <p > <img width = 640 height = 484 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . ambWith . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable ambWith ( CompletableSource other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return ambArray ( this , other ) ; }


Input: Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to the { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Observable < T > andThen ( ObservableSource < T > next ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableAndThenObservable < T > ( this , next ) ) ; }


Input: Returns a Flowable which will subscribe to this Completable and once that is completed then will subscribe to the { [CODESPLIT] @ CheckReturnValue @ NonNull @ BackpressureSupport ( BackpressureKind . FULL ) @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Flowable < T > andThen ( Publisher < T > next ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableAndThenPublisher < T > ( this , next ) ) ; }


Input: Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to the { @code next } SingleSource . An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Single . <p > <img width = 640 height = 437 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . andThen . s . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code andThen } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Single < T > andThen ( SingleSource < T > next ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; return RxJavaPlugins . onAssembly ( new SingleDelayWithCompletable < T > ( next , this ) ) ; }


Input: Returns a { @link Maybe } which will subscribe to this Completable and once that is completed then will subscribe to the { @code next } MaybeSource . An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Maybe . <p > <img width = 640 height = 280 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . andThen . m . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code andThen } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Maybe < T > andThen ( MaybeSource < T > next ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; return RxJavaPlugins . onAssembly ( new MaybeDelayWithCompletable < T > ( next , this ) ) ; }


Input: Returns a Completable that first runs this Completable and then the other completable . <p > <img width = 640 height = 437 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . andThen . c . png alt = > <p > This is an alias for { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable andThen ( CompletableSource next ) { ObjectHelper . requireNonNull ( next , "next is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableAndThenCompletable ( this , next ) ) ; }


Input: Calls the specified converter function during assembly time and returns its resulting value . <p > <img width = 640 height = 751 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . as . png alt = > <p > This allows fluent conversion to any other type . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final < R > R as ( @ NonNull CompletableConverter < ? extends R > converter ) { return ObjectHelper . requireNonNull ( converter , "converter is null" ) . apply ( this ) ; }


Input: Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted . <p > <img width = 640 height = 432 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . blockingAwait . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ SchedulerSupport ( SchedulerSupport . NONE ) public final void blockingAwait ( ) { BlockingMultiObserver < Void > observer = new BlockingMultiObserver < Void > ( ) ; subscribe ( observer ) ; observer . blockingGet ( ) ; }


Input: Calls the given transformer function with this instance and returns the function s resulting Completable . <p > <img width = 640 height = 625 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . compose . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable compose ( CompletableTransformer transformer ) { return wrap ( ObjectHelper . requireNonNull ( transformer , "transformer is null" ) . apply ( this ) ) ; }


Input: Concatenates this Completable with another Completable . <p > <img width = 640 height = 317 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . concatWith . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable concatWith ( CompletableSource other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableAndThenCompletable ( this , other ) ) ; }


Input: Returns a Completable which delays the emission of the completion event by the given time while running on the specified scheduler . <p > <img width = 640 height = 313 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . delay . s . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable delay ( long delay , TimeUnit unit , Scheduler scheduler ) { return delay ( delay , unit , scheduler , false ) ; }


Input: Returns a Completable which delays the emission of the completion event and optionally the error as well by the given time while running on the specified scheduler . <p > <img width = 640 height = 253 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . delay . sb . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable delay ( final long delay , final TimeUnit unit , final Scheduler scheduler , final boolean delayError ) { ObjectHelper . requireNonNull ( unit , "unit is null" ) ; ObjectHelper . requireNonNull ( scheduler , "scheduler is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableDelay ( this , delay , unit , scheduler , delayError ) ) ; }


Input: Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time . <p > <img width = 640 height = 475 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . delaySubscription . t . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > This version of { @code delaySubscription } operates by default on the { @code computation } { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ Experimental @ SchedulerSupport ( SchedulerSupport . COMPUTATION ) public final Completable delaySubscription ( long delay , TimeUnit unit ) { return delaySubscription ( delay , unit , Schedulers . computation ( ) ) ; }


Input: Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time both waiting and subscribing on a given Scheduler . <p > <img width = 640 height = 420 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . delaySubscription . ts . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > You specify which { @link Scheduler } this operator will use . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ Experimental @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable delaySubscription ( long delay , TimeUnit unit , Scheduler scheduler ) { return Completable . timer ( delay , unit , scheduler ) . andThen ( this ) ; }


Input: Returns a Completable which calls the given onComplete callback if this Completable completes . <p > <img width = 640 height = 304 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . doOnComplete . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doOnComplete ( Action onComplete ) { return doOnLifecycle ( Functions . emptyConsumer ( ) , Functions . emptyConsumer ( ) , onComplete , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION ) ; }


Input: Calls the shared { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doOnDispose ( Action onDispose ) { return doOnLifecycle ( Functions . emptyConsumer ( ) , Functions . emptyConsumer ( ) , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , onDispose ) ; }


Input: Returns a Completable which calls the given onError callback if this Completable emits an error . <p > <img width = 640 height = 304 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . doOnError . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doOnError ( Consumer < ? super Throwable > onError ) { return doOnLifecycle ( Functions . emptyConsumer ( ) , onError , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION ) ; }


Input: Returns a Completable instance that calls the various callbacks on the specific lifecycle events . <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) private Completable doOnLifecycle ( final Consumer < ? super Disposable > onSubscribe , final Consumer < ? super Throwable > onError , final Action onComplete , final Action onTerminate , final Action onAfterTerminate , final Action onDispose ) { ObjectHelper . requireNonNull ( onSubscribe , "onSubscribe is null" ) ; ObjectHelper . requireNonNull ( onError , "onError is null" ) ; ObjectHelper . requireNonNull ( onComplete , "onComplete is null" ) ; ObjectHelper . requireNonNull ( onTerminate , "onTerminate is null" ) ; ObjectHelper . requireNonNull ( onAfterTerminate , "onAfterTerminate is null" ) ; ObjectHelper . requireNonNull ( onDispose , "onDispose is null" ) ; return RxJavaPlugins . onAssembly ( new CompletablePeek ( this , onSubscribe , onError , onComplete , onTerminate , onAfterTerminate , onDispose ) ) ; }


Input: Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription . <p > <img width = 640 height = 304 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . doOnSubscribe . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doOnSubscribe ( Consumer < ? super Disposable > onSubscribe ) { return doOnLifecycle ( onSubscribe , Functions . emptyConsumer ( ) , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION ) ; }


Input: Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exception . <p > <img width = 640 height = 304 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . doOnTerminate . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doOnTerminate ( final Action onTerminate ) { return doOnLifecycle ( Functions . emptyConsumer ( ) , Functions . emptyConsumer ( ) , Functions . EMPTY_ACTION , onTerminate , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION ) ; }


Input: Returns a Completable instance that calls the given onTerminate callback after this Completable completes normally or with an exception . <p > <img width = 640 height = 304 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . doAfterTerminate . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable doAfterTerminate ( final Action onAfterTerminate ) { return doOnLifecycle ( Functions . emptyConsumer ( ) , Functions . emptyConsumer ( ) , Functions . EMPTY_ACTION , Functions . EMPTY_ACTION , onAfterTerminate , Functions . EMPTY_ACTION ) ; }


Input: Returns a Completable which emits the terminal events from the thread of the specified scheduler . <p > <img width = 640 height = 523 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . observeOn . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable observeOn ( final Scheduler scheduler ) { ObjectHelper . requireNonNull ( scheduler , "scheduler is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableObserveOn ( this , scheduler ) ) ; }


Input: Returns a Completable instance that if this Completable emits an error and the predicate returns true it will emit an onComplete and swallow the throwable . <p > <img width = 640 height = 283 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . onErrorComplete . f . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable onErrorComplete ( final Predicate < ? super Throwable > predicate ) { ObjectHelper . requireNonNull ( predicate , "predicate is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableOnErrorComplete ( this , predicate ) ) ; }


Input: Returns a Completable instance that when encounters an error from this Completable calls the specified mapper function that returns another Completable instance for it and resumes the execution with it . <p > <img width = 640 height = 426 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . onErrorResumeNext . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable onErrorResumeNext ( final Function < ? super Throwable , ? extends CompletableSource > errorMapper ) { ObjectHelper . requireNonNull ( errorMapper , "errorMapper is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableResumeNext ( this , errorMapper ) ) ; }


Input: Returns a Completable that subscribes repeatedly at most the given times to this Completable . <p > <img width = 640 height = 408 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . repeat . n . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable repeat ( long times ) { return fromPublisher ( toFlowable ( ) . repeat ( times ) ) ; }


Input: Returns a Completable that repeatedly subscribes to this Completable so long as the given stop supplier returns false . <p > <img width = 640 height = 381 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . repeatUntil . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable repeatUntil ( BooleanSupplier stop ) { return fromPublisher ( toFlowable ( ) . repeatUntil ( stop ) ) ; }


Input: Returns a Completable instance that repeats when the Publisher returned by the handler emits an item or completes when this Publisher emits a completed event . <p > <img width = 640 height = 586 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . repeatWhen . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable repeatWhen ( Function < ? super Flowable < Object > , ? extends Publisher < ? > > handler ) { return fromPublisher ( toFlowable ( ) . repeatWhen ( handler ) ) ; }


Input: Returns a Completable that retries this Completable in case of an error as long as the predicate returns true . <p > <img width = 640 height = 325 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . retry . ff . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable retry ( BiPredicate < ? super Integer , ? super Throwable > predicate ) { return fromPublisher ( toFlowable ( ) . retry ( predicate ) ) ; }


Input: Returns a Completable that when this Completable emits an error retries at most the given number of times before giving up and emitting the last error . <p > <img width = 640 height = 451 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . retry . n . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable retry ( long times ) { return fromPublisher ( toFlowable ( ) . retry ( times ) ) ; }


Input: Returns a Completable that when this Completable emits an error retries at most times or until the predicate returns false whichever happens first and emitting the last error . <p > <img width = 640 height = 361 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . retry . nf . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable retry ( long times , Predicate < ? super Throwable > predicate ) { return fromPublisher ( toFlowable ( ) . retry ( times , predicate ) ) ; }


Input: Returns a Completable which given a Publisher and when this Completable emits an error delivers that error through a Flowable and the Publisher should signal a value indicating a retry in response or a terminal event indicating a termination . <p > <img width = 640 height = 586 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . retryWhen . png alt = > <p > Note that the inner { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable retryWhen ( Function < ? super Flowable < Throwable > , ? extends Publisher < ? > > handler ) { return fromPublisher ( toFlowable ( ) . retryWhen ( handler ) ) ; }


Input: Returns an Observable which first delivers the events of the other Observable then runs this CompletableConsumable . <p > <img width = 640 height = 289 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . startWith . o . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Observable < T > startWith ( Observable < T > other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return other . concatWith ( this . < T > toObservable ( ) ) ; }


Input: Subscribes to this CompletableConsumable and returns a Disposable which can be used to dispose the subscription . <p > <img width = 640 height = 352 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . subscribe . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ SchedulerSupport ( SchedulerSupport . NONE ) public final Disposable subscribe ( ) { EmptyCompletableObserver observer = new EmptyCompletableObserver ( ) ; subscribe ( observer ) ; return observer ; }


Input: Subscribes a given CompletableObserver ( subclass ) to this Completable and returns the given CompletableObserver as is . <p > <img width = 640 height = 349 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . subscribeWith . png alt = > <p > Usage example : <pre > <code > Completable source = Completable . complete () . delay ( 1 TimeUnit . SECONDS ) ; CompositeDisposable composite = new CompositeDisposable () ; [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final < E extends CompletableObserver > E subscribeWith ( E observer ) { subscribe ( observer ) ; return observer ; }


Input: Returns a Completable which subscribes the child subscriber on the specified scheduler making sure the subscription side - effects happen on that specific thread of the scheduler . <p > <img width = 640 height = 686 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . subscribeOn . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable subscribeOn ( final Scheduler scheduler ) { ObjectHelper . requireNonNull ( scheduler , "scheduler is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableSubscribeOn ( this , scheduler ) ) ; }


Input: Terminates the downstream if this or the other { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . NONE ) public final Completable takeUntil ( CompletableSource other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return RxJavaPlugins . onAssembly ( new CompletableTakeUntilCompletable ( this , other ) ) ; }


Input: Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn t complete within the given time . <p > <img width = 640 height = 348 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . timeout . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . COMPUTATION ) public final Completable timeout ( long timeout , TimeUnit unit ) { return timeout0 ( timeout , unit , Schedulers . computation ( ) , null ) ; }


Input: Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn t complete within the given time . <p > <img width = 640 height = 308 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . timeout . c . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . COMPUTATION ) public final Completable timeout ( long timeout , TimeUnit unit , CompletableSource other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return timeout0 ( timeout , unit , Schedulers . computation ( ) , other ) ; }


Input: Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn t complete within the given time while waiting on the specified Scheduler . <p > <img width = 640 height = 348 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . timeout . s . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable timeout ( long timeout , TimeUnit unit , Scheduler scheduler ) { return timeout0 ( timeout , unit , scheduler , null ) ; }


Input: Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn t complete within the given time while waiting on the specified scheduler . <p > <img width = 640 height = 308 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . timeout . sc . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ NonNull @ SchedulerSupport ( SchedulerSupport . CUSTOM ) public final Completable timeout ( long timeout , TimeUnit unit , Scheduler scheduler , CompletableSource other ) { ObjectHelper . requireNonNull ( other , "other is null" ) ; return timeout0 ( timeout , unit , scheduler , other ) ; }


Input: Allows fluent conversion to another type via a function callback . <p > <img width = 640 height = 751 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . to . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { [CODESPLIT] @ CheckReturnValue @ SchedulerSupport ( SchedulerSupport . NONE ) public final < U > U to ( Function < ? super Completable , U > converter ) { try { return ObjectHelper . requireNonNull ( converter , "converter is null" ) . apply ( this ) ; } catch ( Throwable ex ) { Exceptions . throwIfFatal ( ex ) ; throw ExceptionHelper . wrapOrThrow ( ex ) ; } }


Input: Returns a Flowable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber . <p > <img width = 640 height = 585 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . toFlowable . png alt = > <dl > <dt > <b > Backpressure : < / b > < / dt > <dd > The returned { [CODESPLIT] @ CheckReturnValue @ SuppressWarnings ( "unchecked" ) @ BackpressureSupport ( BackpressureKind . FULL ) @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Flowable < T > toFlowable ( ) { if ( this instanceof FuseToFlowable ) { return ( ( FuseToFlowable < T > ) this ) . fuseToFlowable ( ) ; } return RxJavaPlugins . onAssembly ( new CompletableToFlowable < T > ( this ) ) ; }


Input: Converts this Completable into a { @link Maybe } . <p > <img width = 640 height = 585 src = https : // raw . github . com / wiki / ReactiveX / RxJava / images / rx - operators / Completable . toMaybe . png alt = > <dl > <dt > <b > Scheduler : < / b > < / dt > <dd > { @code toMaybe } does not operate by default on a particular { @link Scheduler } . < / dd > < / dl > [CODESPLIT] @ CheckReturnValue @ SuppressWarnings ( "unchecked" ) @ SchedulerSupport ( SchedulerSupport . NONE ) public final < T > Maybe < T > toMaybe ( ) { if ( this instanceof FuseToMaybe ) { return ( ( FuseToMaybe < T > ) this ) . fuseToMaybe ( ) ; } return RxJavaPlugins . onAssembly ( new MaybeFromCompletable < T > ( this ) ) ; }


Input: Try subscribing to a { [CODESPLIT] static < T > boolean tryAsCompletable ( Object source , Function < ? super T , ? extends CompletableSource > mapper , CompletableObserver observer ) { if ( source instanceof Callable ) { @ SuppressWarnings ( "unchecked" ) Callable < T > call = ( Callable < T > ) source ; CompletableSource cs = null ; try { T item = call . call ( ) ; if ( item != null ) { cs = ObjectHelper . requireNonNull ( mapper . apply ( item ) , "The mapper returned a null CompletableSource" ) ; } } catch ( Throwable ex ) { Exceptions . throwIfFatal ( ex ) ; EmptyDisposable . error ( ex , observer ) ; return true ; } if ( cs == null ) { EmptyDisposable . complete ( observer ) ; } else { cs . subscribe ( observer ) ; } return true ; } return false ; }


Input: Try subscribing to a { [CODESPLIT] static < T , R > boolean tryAsMaybe ( Object source , Function < ? super T , ? extends MaybeSource < ? extends R > > mapper , Observer < ? super R > observer ) { if ( source instanceof Callable ) { @ SuppressWarnings ( "unchecked" ) Callable < T > call = ( Callable < T > ) source ; MaybeSource < ? extends R > cs = null ; try { T item = call . call ( ) ; if ( item != null ) { cs = ObjectHelper . requireNonNull ( mapper . apply ( item ) , "The mapper returned a null MaybeSource" ) ; } } catch ( Throwable ex ) { Exceptions . throwIfFatal ( ex ) ; EmptyDisposable . error ( ex , observer ) ; return true ; } if ( cs == null ) { EmptyDisposable . complete ( observer ) ; } else { cs . subscribe ( MaybeToObservable . create ( observer ) ) ; } return true ; } return false ; }


Input: Adds a new element to this list . [CODESPLIT] public void add ( Object o ) { // if no value yet, create the first array if ( size == 0 ) { head = new Object [ capacityHint + 1 ] ; tail = head ; head [ 0 ] = o ; indexInTail = 1 ; size = 1 ; } else // if the tail is full, create a new tail and link if ( indexInTail == capacityHint ) { Object [ ] t = new Object [ capacityHint + 1 ] ; t [ 0 ] = o ; tail [ capacityHint ] = t ; tail = t ; indexInTail = 1 ; size ++ ; } else { tail [ indexInTail ] = o ; indexInTail ++ ; size ++ ; } }


Input: Stops the purge thread . [CODESPLIT] public static void shutdown ( ) { ScheduledExecutorService exec = PURGE_THREAD . getAndSet ( null ) ; if ( exec != null ) { exec . shutdownNow ( ) ; } POOLS . clear ( ) ; }


Input: Creates a ScheduledExecutorService with the given factory . [CODESPLIT] public static ScheduledExecutorService create ( ThreadFactory factory ) { final ScheduledExecutorService exec = Executors . newScheduledThreadPool ( 1 , factory ) ; tryPutIntoPool ( PURGE_ENABLED , exec ) ; return exec ; }


Input: Atomically sets a new subscription . [CODESPLIT] public final void setSubscription ( Subscription s ) { if ( cancelled ) { s . cancel ( ) ; return ; } ObjectHelper . requireNonNull ( s , "s is null" ) ; if ( get ( ) == 0 && compareAndSet ( 0 , 1 ) ) { Subscription a = actual ; if ( a != null && cancelOnReplace ) { a . cancel ( ) ; } actual = s ; long r = requested ; if ( decrementAndGet ( ) != 0 ) { drainLoop ( ) ; } if ( r != 0L ) { s . request ( r ) ; } return ; } Subscription a = missedSubscription . getAndSet ( s ) ; if ( a != null && cancelOnReplace ) { a . cancel ( ) ; } drain ( ) ; }


Input: Loops until all notifications in the queue has been processed . [CODESPLIT] void emitLoop ( ) { for ( ; ; ) { AppendOnlyLinkedArrayList < Object > q ; synchronized ( this ) { q = queue ; if ( q == null ) { emitting = false ; return ; } queue = null ; } q . forEachWhile ( this ) ; } }


Input: TODO fuse back to Flowable [CODESPLIT] @ Override protected void subscribeActual ( SingleObserver < ? super T > observer ) { source . subscribe ( new LastSubscriber < T > ( observer , defaultItem ) ) ; }


Input: Throws a particular { @code Throwable } only if it belongs to a set of fatal error varieties . These varieties are as follows : <ul > <li > { @code VirtualMachineError } < / li > <li > { @code ThreadDeath } < / li > <li > { @code LinkageError } < / li > < / ul > This can be useful if you are writing an operator that calls user - supplied code and you want to notify subscribers of errors encountered in that code by calling their { @code onError } methods but only if the errors are not so catastrophic that such a call would be futile in which case you simply want to rethrow the error . [CODESPLIT] public static void throwIfFatal ( @ NonNull Throwable t ) { // values here derived from https://github.com/ReactiveX/RxJava/issues/748#issuecomment-32471495 if ( t instanceof VirtualMachineError ) { throw ( VirtualMachineError ) t ; } else if ( t instanceof ThreadDeath ) { throw ( ThreadDeath ) t ; } else if ( t instanceof LinkageError ) { throw ( LinkageError ) t ; } }


Input: If the provided Throwable is an Error this method throws it otherwise returns a RuntimeException wrapping the error if that error is a checked exception . [CODESPLIT] public static RuntimeException wrapOrThrow ( Throwable error ) { if ( error instanceof Error ) { throw ( Error ) error ; } if ( error instanceof RuntimeException ) { return ( RuntimeException ) error ; } return new RuntimeException ( error ) ; }


Input: Returns a flattened list of Throwables from tree - like CompositeException chain . [CODESPLIT] public static List < Throwable > flatten ( Throwable t ) { List < Throwable > list = new ArrayList < Throwable > ( ) ; ArrayDeque < Throwable > deque = new ArrayDeque < Throwable > ( ) ; deque . offer ( t ) ; while ( ! deque . isEmpty ( ) ) { Throwable e = deque . removeFirst ( ) ; if ( e instanceof CompositeException ) { CompositeException ce = ( CompositeException ) e ; List < Throwable > exceptions = ce . getExceptions ( ) ; for ( int i = exceptions . size ( ) - 1 ; i >= 0 ; i -- ) { deque . offerFirst ( exceptions . get ( i ) ) ; } } else { list . add ( e ) ; } } return list ; }


Input: Workaround for Java 6 not supporting throwing a final Throwable from a catch block . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) public static < E extends Throwable > Exception throwIfThrowable ( Throwable e ) throws E { if ( e instanceof Exception ) { return ( Exception ) e ; } throw ( E ) e ; }


Input: Atomically adds the consumer to the { [CODESPLIT] void add ( CacheDisposable < T > consumer ) { for ( ; ; ) { CacheDisposable < T > [ ] current = observers . get ( ) ; if ( current == TERMINATED ) { return ; } int n = current . length ; @ SuppressWarnings ( "unchecked" ) CacheDisposable < T > [ ] next = new CacheDisposable [ n + 1 ] ; System . arraycopy ( current , 0 , next , 0 , n ) ; next [ n ] = consumer ; if ( observers . compareAndSet ( current , next ) ) { return ; } } }


Input: Atomically removes the consumer from the { [CODESPLIT] @ SuppressWarnings ( "unchecked" ) void remove ( CacheDisposable < T > consumer ) { for ( ; ; ) { CacheDisposable < T > [ ] current = observers . get ( ) ; int n = current . length ; if ( n == 0 ) { return ; } int j = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( current [ i ] == consumer ) { j = i ; break ; } } if ( j < 0 ) { return ; } CacheDisposable < T > [ ] next ; if ( n == 1 ) { next = EMPTY ; } else { next = new CacheDisposable [ n - 1 ] ; System . arraycopy ( current , 0 , next , 0 , j ) ; System . arraycopy ( current , j + 1 , next , j , n - j - 1 ) ; } if ( observers . compareAndSet ( current , next ) ) { return ; } } }


Input: Replays the contents of this cache to the given consumer based on its current state and number of items requested by it . [CODESPLIT] void replay ( CacheDisposable < T > consumer ) { // make sure there is only one replay going on at a time if ( consumer . getAndIncrement ( ) != 0 ) { return ; } // see if there were more replay request in the meantime int missed = 1 ; // read out state into locals upfront to avoid being re-read due to volatile reads long index = consumer . index ; int offset = consumer . offset ; Node < T > node = consumer . node ; Observer < ? super T > downstream = consumer . downstream ; int capacity = capacityHint ; for ( ; ; ) { // if the consumer got disposed, clear the node and quit if ( consumer . disposed ) { consumer . node = null ; return ; } // first see if the source has terminated, read order matters! boolean sourceDone = done ; // and if the number of items is the same as this consumer has received boolean empty = size == index ; // if the source is done and we have all items so far, terminate the consumer if ( sourceDone && empty ) { // release the node object to avoid leaks through retained consumers consumer . node = null ; // if error is not null then the source failed Throwable ex = error ; if ( ex != null ) { downstream . onError ( ex ) ; } else { downstream . onComplete ( ) ; } return ; } // there are still items not sent to the consumer if ( ! empty ) { // if the offset in the current node has reached the node capacity if ( offset == capacity ) { // switch to the subsequent node node = node . next ; // reset the in-node offset offset = 0 ; } // emit the cached item downstream . onNext ( node . values [ offset ] ) ; // move the node offset forward offset ++ ; // move the total consumed item count forward index ++ ; // retry for the next item/terminal event if any continue ; } // commit the changed references back consumer . index = index ; consumer . offset = offset ; consumer . node = node ; // release the changes and see if there were more replay request in the meantime missed = consumer . addAndGet ( - missed ) ; if ( missed == 0 ) { break ; } } }


Input: flatMap [CODESPLIT] @ Benchmark public void oneStreamOfNthatMergesIn1 ( final InputMillion input ) throws InterruptedException { Flowable < Flowable < Integer >> os = Flowable . range ( 1 , input . size ) . map ( new Function < Integer , Flowable < Integer > > ( ) { @ Override public Flowable < Integer > apply ( Integer v ) { return Flowable . just ( v ) ; } } ) ; PerfSubscriber o = input . newLatchedObserver ( ) ; Flowable . merge ( os ) . subscribe ( o ) ; if ( input . size == 1 ) { while ( o . latch . getCount ( ) != 0 ) { } } else { o . latch . await ( ) ; } }


Input: Adds a disposable to this container or disposes it if the container has been disposed . [CODESPLIT] @ Override public boolean add ( @ NonNull Disposable disposable ) { ObjectHelper . requireNonNull ( disposable , "disposable is null" ) ; if ( ! disposed ) { synchronized ( this ) { if ( ! disposed ) { OpenHashSet < Disposable > set = resources ; if ( set == null ) { set = new OpenHashSet < Disposable > ( ) ; resources = set ; } set . add ( disposable ) ; return true ; } } } disposable . dispose ( ) ; return false ; }


Input: Atomically adds the given array of Disposables to the container or disposes them all if the container has been disposed . [CODESPLIT] public boolean addAll ( @ NonNull Disposable ... disposables ) { ObjectHelper . requireNonNull ( disposables , "disposables is null" ) ; if ( ! disposed ) { synchronized ( this ) { if ( ! disposed ) { OpenHashSet < Disposable > set = resources ; if ( set == null ) { set = new OpenHashSet < Disposable > ( disposables . length + 1 ) ; resources = set ; } for ( Disposable d : disposables ) { ObjectHelper . requireNonNull ( d , "A Disposable in the disposables array is null" ) ; set . add ( d ) ; } return true ; } } } for ( Disposable d : disposables ) { d . dispose ( ) ; } return false ; }


Input: Removes and disposes the given disposable if it is part of this container . [CODESPLIT] @ Override public boolean remove ( @ NonNull Disposable disposable ) { if ( delete ( disposable ) ) { disposable . dispose ( ) ; return true ; } return false ; }


Input: Removes ( but does not dispose ) the given disposable if it is part of this container . [CODESPLIT] @ Override public boolean delete ( @ NonNull Disposable disposable ) { ObjectHelper . requireNonNull ( disposable , "disposables is null" ) ; if ( disposed ) { return false ; } synchronized ( this ) { if ( disposed ) { return false ; } OpenHashSet < Disposable > set = resources ; if ( set == null || ! set . remove ( disposable ) ) { return false ; } } return true ; }


Input: Atomically clears the container then disposes all the previously contained Disposables . [CODESPLIT] public void clear ( ) { if ( disposed ) { return ; } OpenHashSet < Disposable > set ; synchronized ( this ) { if ( disposed ) { return ; } set = resources ; resources = null ; } dispose ( set ) ; }


Input: Returns the number of currently held Disposables . [CODESPLIT] public int size ( ) { if ( disposed ) { return 0 ; } synchronized ( this ) { if ( disposed ) { return 0 ; } OpenHashSet < Disposable > set = resources ; return set != null ? set . size ( ) : 0 ; } }


Input: Subscribes to the source and calls the Subscriber methods on the current thread . <p > [CODESPLIT] public static < T > void subscribe ( Publisher < ? extends T > o , Subscriber < ? super T > subscriber ) { final BlockingQueue < Object > queue = new LinkedBlockingQueue < Object > ( ) ; BlockingSubscriber < T > bs = new BlockingSubscriber < T > ( queue ) ; o . subscribe ( bs ) ; try { for ( ; ; ) { if ( bs . isCancelled ( ) ) { break ; } Object v = queue . poll ( ) ; if ( v == null ) { if ( bs . isCancelled ( ) ) { break ; } BlockingHelper . verifyNonBlocking ( ) ; v = queue . take ( ) ; } if ( bs . isCancelled ( ) ) { break ; } if ( v == BlockingSubscriber . TERMINATED || NotificationLite . acceptFull ( v , subscriber ) ) { break ; } } } catch ( InterruptedException e ) { bs . cancel ( ) ; subscriber . onError ( e ) ; } }


Input: Runs the source observable to a terminal event ignoring any values and rethrowing any exception . [CODESPLIT] public static < T > void subscribe ( Publisher < ? extends T > o ) { BlockingIgnoringReceiver callback = new BlockingIgnoringReceiver ( ) ; LambdaSubscriber < T > ls = new LambdaSubscriber < T > ( Functions . emptyConsumer ( ) , callback , callback , Functions . REQUEST_MAX ) ; o . subscribe ( ls ) ; BlockingHelper . awaitForComplete ( callback , ls ) ; Throwable e = callback . error ; if ( e != null ) { throw ExceptionHelper . wrapOrThrow ( e ) ; } }


Input: Subscribes to the source and calls the given actions on the current thread . [CODESPLIT] public static < T > void subscribe ( Publisher < ? extends T > o , final Consumer < ? super T > onNext , final Consumer < ? super Throwable > onError , final Action onComplete ) { ObjectHelper . requireNonNull ( onNext , "onNext is null" ) ; ObjectHelper . requireNonNull ( onError , "onError is null" ) ; ObjectHelper . requireNonNull ( onComplete , "onComplete is null" ) ; subscribe ( o , new LambdaSubscriber < T > ( onNext , onError , onComplete , Functions . REQUEST_MAX ) ) ; }