Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Created May 19, 2017 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thomvis/1241e5ca9146ddee0b50c81923270cf4 to your computer and use it in GitHub Desktop.
Save Thomvis/1241e5ca9146ddee0b50c81923270cf4 to your computer and use it in GitHub Desktop.
To the person that asked me a question about backpressure after my talk at UIKonf to which I said "Let's talk about it over lunch" and wasn't able to find...

I didn't cover backpressure because it is quite complex and - from my experience - not a core concept of reactive programming for mobile development. Some implementations do have it (e.g. RxJava), but to my knowledge none of the (big) iOS implementations, such as RxSwift and ReactiveSwift, have support for it. I use RxJava, but have never really needed its backpressure capabilities.

Adding backpressure to my minimal reactive programming implementation would require a layer of indirection that would establish the backchannel needed to allow for backpressure. It could look something like this:

o.subscribe { producer in
  producer.observe {
    // $0 is every element as it gets emitted
    producer.request(1) // makes sure the number of requested events stays 5 (requests are additive)
  }
  producer.request(5) // this indicates that this Observer is ready to process 5 events
}

The outer closure would be called immediately. The closure passed to producer.observe is the Observer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment