title: RxJava unsubscribe on Network close
body: <p>i am currently trying to unsubscribe an observable, if the network request is closed, to not further stream the data.</p>
  
  <p>My Observable is created with:</p>
  
  <pre><code>Observable.interval(1, TimeUnit.SECONDS)
  .map { LocalDateTime.now() }.share()
  </code></pre>
  
  <p>So there are multiple subscribers. But I don't know how to unsubscribe if the network is closed.</p>
  
  <p>I am currently stream the data with server-sent event with vert.x to the client like this:</p>
  
  <pre><code>flow.subscribe({
    response.write("the current time is $it")
  }, ::println, {
    response.end()
  })
  </code></pre>
  
  <p>If I cancel the request from the client, the observable will continue to "stream" the data.</p>
  
  <p>thanks for the help</p>