I have a test example with one button. When user presses the button is called RAC_request and request is executing. If user presses this button a many times for a short time, many requests will be execute asynchronously. I want to create logic to previously signal cancelled when new request is executing by Reactive Cocoa. I know that exists switchToLatest
in Reactive Cocoa, but I can't do that logic work correctly. How do this by RAC?
Asked
Active
Viewed 229 times
-1

Nikita Ermolenko
- 2,139
- 2
- 19
- 41
1 Answers
1
if user presses the button a many times for a short time, you can use throttle
to set the time. if a interval times have many nextValue, it only take newest. also you can use switchToLatest. There is a easy example, i hole that would be useful for you.
[button.rac_command execute:nil];
button.rac_command = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@"TestSignal"];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
}];
}];
}];
[[[button.rac_command.executionSignals throttle:0.5] switchToLatest]subscribeNext:^(id x) {
NSLog(@"%@", x);
}];

chaoxn
- 103
- 1
- 8
-
Thank you for answering, but I have a bit another situation. I have to call request when I get applicationDidBecomeActiveNotification, it's just a request which update user timezone. And if user so often hide/show application with bad internet connection current updateRequest should cancels previously request. I hope you understand my problem. – Nikita Ermolenko Jan 14 '16 at 06:40
-
@NikitaErmolenko ry to create a RACSignal in appDelegate, and activate it in applicationDidBecomeActive. Then you can deal with the signal by switchToLatest or throttle – chaoxn Jan 14 '16 at 08:19
-
sorry, but I spent a lot of time and cannot do this :( Can you show some code for my case? It will save a lot of time for me! – Nikita Ermolenko Jan 14 '16 at 08:52