objective c - How to merge multiple signal and stop on first next but not to stop on first error? -
i have number of network requests , 1 or more of them return valid data , possible return error. how can combine request stop once first valid returned data not stop in case of error.
i have try this:
[[racsignal merge:@[sigone, sigtwo, sigthree]] subscribenext:^(ractuple *mydata){ nslog(@"data received"); } error:^(nserror *error) { nslog(@"e %@", error); } completed:^{ nslog(@"they're done!"); } ];
my problems:
- if 1 of signals returns first error no next send. not desired because 1 of other signals return valid data.
- if 3 return valid data subscribenext called 3 times stop got valid data (to reduce network traffic)
try this:
[[[[racsignal merge:@[[sigone catchto:[racsignal empty]], [sigtwo catchto:[racsignal empty]], [sigthree catchto:[racsignal empty]]]] repeat] take:1] subscribenext:^(ractuple *mydata){ nslog(@"data received"); } error:^(nserror *error) { nslog(@"e %@", error); } completed:^{ nslog(@"they're done!"); } ];
by using catchto:
, signals being replaced empty signal when error, causes signal send complete
, , doesn't end subscription every other signal. adding repeat, we're getting signal run again if no next
events occurred (because of signals errored). adding take:1
, signal complete once single next
event received.
Comments
Post a Comment