ios - ReactiveCocoa: How to prevent RACSignal from being executed twice in parallel? -
in app use reactivecocoa , afnetworking-extension api-calls. each api-endpoint have method starting api-request , returning racsignal.
with results of api-calls populate uitableviews.
there multiple events, result in reloading/refreshing view per api-request:
- at launch of application
- viewdidappear in every tab
- when user uses pulltorefresh
- when app decides new data @ anytime
how can prevent, new api-requests executed before executing request same endpoint has finished?
i know, can use "throttle" throttle user-inputs tap-events. mentioned there several occasions can start new api-request.
i work flags, set when starting request , resetted in "completed"-block.
but there built-in methods in reactivecocoa use instead of?
as @jakub-vanu mention raccommand friend here.
you can have raccommand returns signal sends results of network request next events.
let apifetchcommand: raccommand = raccommand(signalblock: { [weak self](object: anyobject!) -> racsignal! in return self.fetchsignal() })
then if want signal sends next events come commmand can user executionsignals
property on raccommand.
let fetchedresultssignal: racsignal = self.apifetchcommand.executionsignals.switchtolatest()
this signal can used listen results command.
raccommands have property called allowsconcurrentexecution
defaulted false. means command not fire if signal returns has not yet completed.
then execute command call
self.apifetchcommand.execute(someobject)
Comments
Post a Comment