Pipe for repeating network requests in Reactive Cocoa 4
<p>I want to refresh data every 15 seconds from an API using Reactive Cocoa 4. Since more than one subscriber can ask for this data at the same time, I want to have multiple subscribers to share one source of data. </p>

<p>My current approach is to have one <code>Signal</code> and share it to every instance that asks for the data. This Signal should start refreshing as soon as the first Signal is subscribed and end after the last has disposed.</p>

<pre><code>SignalProducer&lt;String, NoError&gt; { observer, disposable in
    self.disposable = self.repeatTimer.observeNext { _ in
        NSLog("start network request")
            observer.sendNext("result")
        }
        }.on(disposed: {
            NSLog("disposed")
        }).startWithSignal { signal, disposable1 in
            self.updateSignal = signal
        }
    }

    return (updateSignal, disposable!)
</code></pre>

<p>So for the first request I create and store the updateSignal and each following request will get that signal.</p>

<p>My first question: How can I know when the last subscriber disposed its signal? So when can I stop the requests? </p>

<p>My second question: I store the disposable from my repeatin network request in <code>self.disposable</code> which I also return to the subscriber. If the subscriber only disposes its Signal (which he got from <code>Signal.observeNext()</code>) the inner loop, where I log "start network request" is running endless. Do I really need to stop that Signal myself even when the outer Signal gets disposed?</p>

<p>Is there any nicer way or pattern for shared repeating requests?</p>