title: How to create backpressure in an RxJava2 operator that emits varying number of items
body: <p>I'm trying to create a few backpressure honoring operations for a Flowable in RxJava2.</p>
  
  <p>Specifically, I'm parsing an XML document: I have a Flowable streams of byte[], and transforming it into XMLEvents (tag start, tag end, piece of content, that kind of thing)</p>
  
  <p>Without the backpressure, it is working fine, like in this RxJava1 operator:
  <a href="https://github.com/flyaruu/xml-rx/blob/master/src/main/java/nl/codemonkey/xml_aalto_rxjava/XML.java" rel="nofollow noreferrer">https://github.com/flyaruu/xml-rx/blob/master/src/main/java/nl/codemonkey/xml_aalto_rxjava/XML.java</a></p>
  
  <p>I'm porting this to RxJava2, and want to add backpressure capability, but I really struggle. </p>
  
  <p>I'm looking at this section: <a href="https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0#request-accounting" rel="nofollow noreferrer">https://github.com/ReactiveX/RxJava/wiki/Writing-operators-for-2.0#request-accounting</a></p>
  
  <p>There is an example of the RebatchRequests using a drain method, but I can't really figure out all the one-letter variables, the optimized code, what is generic 'drain' code and what is specific to RebatchRequests and even what concepts upstream and downstream even means in this context.</p>
  
  <p>I have a feeling I'm missing something obvious, as what I'm trying to do seems pretty generic: I consume an item, a byte[] in this case, and that results in zero-or-more XMLEvents. Based on that number of items I need to rebalance the requests. Is there an example out there that does this? Or some tutorial?</p>