title: flattenMap and error handling in ReactiveCocoa with swift
body: <p>After reading the following tutorial <a href="http://www.scottlogic.com/blog/2014/07/24/mvvm-reactivecocoa-swift.html" rel="nofollow">http://www.scottlogic.com/blog/2014/07/24/mvvm-reactivecocoa-swift.html</a> I am trying to use ReactiveCocoa with Swift with in of my apps. When button is pressed I am making a request to check if server is responding:</p>
  
  <pre><code>_checkButton.rac_signalForControlEvents(UIControlEvents.TouchUpInside)
  .flattenMap({(text: AnyObject!) -&gt; RACStream! in
    return RACSignal.createSignal({ (subscriber: RACSubscriber!) -&gt; RACDisposable! in
      Alamofire.request(.GET, "http://google.com")
      .validate(statusCode: 200..&lt;300)
      .response{ (_, _, _, error) in
        if(error == nil) {
          subscriber.sendNext(true)
          subscriber.sendCompleted()
        } else {
          subscriber.sendError(error)
        }
      })
  }).subscribeNextAs({ (value: AnyObject) -&gt; () in
    println("success")
  }, error: { (error: NSError) -&gt; () in
    println("error")
  }, completed: {})
  </code></pre>
  
  <p>When <code>sendError()</code> is called in <code>flattenMap</code> the signal is no more emmited when I am pressing the button. It works correctly as long as I am emitting <code>sendNext()</code> and <code>sendCompleted()</code> only.</p>
  
  <p>Any clue on how to resolve this will be appreciated.</p>