Source:
void drain() { if (wip.getAndIncrement() != 0) { return; } int missed = 1; final AtomicLong requested = sharedProducer; final Subscriber<? super R> actualSubscriber = this.actual; final NotificationLite<R> nl = NotificationLite.instance(); for (;;) { if (cancelled) { cleanup(); return; } EagerInnerSubscriber<R> innerSubscriber; boolean outerDone = done; synchronized (subscribers) { innerSubscriber = subscribers.peek(); } boolean empty = innerSubscriber == null; if (outerDone) { Throwable error = this.error; if (error != null) { cleanup(); actualSubscriber.onError(error); return; } else if (empty) { actualSubscriber.onCompleted(); return; } } if (!empty) { long requestedAmount = requested.get(); long emittedAmount = 0L; boolean unbounded = requestedAmount == Long.MAX_VALUE; Queue<Object> innerQueue = innerSubscriber.queue; boolean innerDone = false; for (;;) { outerDone = innerSubscriber.done; Object v = innerQueue.peek(); empty = v == null; if (outerDone) { Throwable innerError = innerSubscriber.error; if (innerError != null) { cleanup(); actualSubscriber.onError(innerError); return; } else if (empty) { synchronized (subscribers) { subscribers.poll(); request(1); } innerSubscriber.unsubscribe(); innerDone = true; break; } } if (empty) { break; } if (requestedAmount == 0L) { break; } innerQueue.poll(); try { actualSubscriber.onNext(nl.getValue(v)); } catch (Throwable ex) { Exceptions.throwOrReport(ex, actualSubscriber, v); return; } requestedAmount--; emittedAmount--; } if (emittedAmount != 0L) { if (!unbounded) { requested.addAndGet(emittedAmount); } if (!innerDone) { innerSubscriber.requestMore(-emittedAmount); } } if (innerDone) { continue; } } missed = wip.addAndGet(-missed); if (missed == 0) { return; } } }

Target:
void drain() { if (wip.getAndIncrement() != 0) { return; } int missed = 1; final AtomicLong requested = sharedProducer; final Subscriber<? super R> actualSubscriber = this.actual; final NotificationLite<R> nl = NotificationLite.instance(); for (;;) { if (cancelled) { cleanup(); return; } EagerInnerSubscriber<R> innerSubscriber; boolean outerDone = done; synchronized (subscribers) { innerSubscriber = subscribers.peek(); } boolean empty = innerSubscriber == null; if (outerDone) { Throwable error = this.error; if (error != null) { cleanup(); actualSubscriber.onError(error); return; } else if (empty) { actualSubscriber.onCompleted(); return; } } if (!empty) { long requestedAmount = requested.get(); long emittedAmount = 0L; boolean unbounded = requestedAmount == Long.MAX_VALUE; Queue<Object> innerQueue = innerSubscriber.queue; boolean innerDone = false; for (;;) { outerDone = innerSubscriber.done; Object v = innerQueue.peek(); empty = v == null; if (outerDone) { Throwable innerError = innerSubscriber.error; if (innerError != null) { cleanup(); actualSubscriber.onError(innerError); return; } else if (empty) { synchronized (subscribers) { subscribers.poll(); } innerSubscriber.unsubscribe(); innerDone = true; request(1); break; } } if (empty) { break; } if (requestedAmount == 0L) { break; } innerQueue.poll(); try { actualSubscriber.onNext(nl.getValue(v)); } catch (Throwable ex) { Exceptions.throwOrReport(ex, actualSubscriber, v); return; } requestedAmount--; emittedAmount--; } if (emittedAmount != 0L) { if (!unbounded) { requested.addAndGet(emittedAmount); } if (!innerDone) { innerSubscriber.requestMore(-emittedAmount); } } if (innerDone) { continue; } } missed = wip.addAndGet(-missed); if (missed == 0) { return; } } }