Nikita Ermolenko Nikita Ermolenko - 1 year ago 151
iOS Question

RACCommand - dispose executing signal

I have a little confused about dispose mechanism of

. I want to dispose subscription of executing signal manually, but
invokes only after
event. It's a problem of my real task, hope someone can help me.

- (void)test {
RACCommand *rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [self signal];

RACDisposable *rac_dispose = [[rac_command execute:nil] subscribeNext:^(id x) {}];
[rac_dispose dispose];

- (RACSignal *)signal {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[subscriber sendNext:nil];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"dispose block");

Answer Source

The subscriptions to the signals that your block parameter (to the initializer) creates are private to the RACCommand, and it offers no API to dispose those subscriptions. The RACCommand will keep that subscription alive until it completes, regardless of whether your dispose of the signal returned from -[RACCommand execute:].

In other words, there is unfortunately no way to do what you are trying to do. If you need the ability to cancel the behavior of the signals that your block parameter creates, consider having those signals check for some condition.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download