title: Limiting concurrent access to a service class with RxSwift
body: <p>Given a service class like this:</p>
  
  <pre><code>class Service {
      let networkService = NetworkService()
  
      func handleJobA(input: String) -&gt; Observable&lt;ResultA&gt; {
          return networkService
              .computeA(input)
              .map { $0.a }
      }
  }
  </code></pre>
  
  <p>And when I use it from the caller side like this:</p>
  
  <pre><code>let service = Service()
  
  Observable
      .from(["Hello", "World"])
      .flatMap {
          service.handleJobA($0)
      }
      .subscribe()
  </code></pre>
  
  <p>Then this would send multiple requests to <code>service</code> at the same time. I wanted for the stream to wait until each request is done. That was achievable using the <code>merge</code> operator.</p>
  
  <pre><code>Observable
      .from(["Hello", "World"])
      .flatMap {
          Observable.just(
              service.handleJobA($0)
          )
      }
      .merge(maxConcurrent: 1)
      .subscribe()
  </code></pre>
  
  <p>So far, so good - the service will not perform multiple <code>handleJobA</code> tasks at the same time. </p>
  
  <p>However, the concurrency is a service detail and the caller should NOT care about it. In fact, the service, at a later stage, might decide to allow for difference concurrency values.</p>
  
  <p>Secondly, when I add a new method <code>handleJobB</code>, it must not be active at the same time as job A, and vice versa.</p>
  
  <p>So my question is:</p>
  
  <ol>
  <li>How can I restrict the maxConcurrency to the handleJobA observable as a implementation detail?</li>
  <li>Which RxSwift pattern would allow to restrict this for any service method?</li>
  </ol>