I have one signal that basically what it does is requesting for a configuration using NSRULSession. When I do a subscribeNext it does the request perfectly fine, however for the second time this request is not necessary anymore. How could I avoid it?
Avoid repeated http requests on ReactiveCocoa
170 views Asked by Hola Soy Edu Feliz Navidad At
3
There are 3 answers
0
On
Your signal will do its work each time it is subscribed to unless you do something explicit to prevent that. It sounds like what you want here is the replayLast operator. This operator will cache the last emitted value of your signal and emit it when your signal is subscribed to again instead of redoing the initial work.
Read up on the 'replay' operators here: http://spin.atomicobject.com/2014/06/29/replay-replaylast-replaylazily/
One time signal could be made via
take:operator. You just need to pass an argument for the amount of times required to perform a signal. After such amount of executions this gateway will be closed completely and no more data will be passed in thesubscribeNext:block. In your case this amount would be equal 1.