Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee to update refresh control on main thread #1942

Merged

Conversation

ryanli-me
Copy link
Contributor

Resolves #1940.

@neilpa
Copy link
Member

neilpa commented Apr 27, 2015

Thanks for the PR!

However I'm not sure we want to make this change. IIRC, signals associated with commands are required to deliver events on the main thread. That means the signal returned from the generator block should be getting the deliverOnMainThread treatment and not here.

@ryanli-me
Copy link
Contributor Author

Oh! I didn't know that the signal returned from the generator block is required to deliver on main thread, thanks!

@kastiglione
Copy link
Member

Actually, RACCommand takes care of delivering on the main thread. The signal returned from the generator block is not required to deliver on main. This is briefly mentioned in the docs. The relevant line of code is here.

@ryanli-me
Copy link
Contributor Author

Isn't that line of code used to deliver executionSignals on main thread but not the return value of -execute:? Sorry, I am not that familiar with ReactiveCocoa yet, if I am wrong. But when I checked if the subscription block is invoked on main thread using [NSThread isMainThread], it gives me NO.

RACDisposable *executionDisposable = [[[[self
    rac_signalForControlEvents:UIControlEventValueChanged]
    map:^(UIRefreshControl *x) {
        return [[[command
            execute:x]
            catchTo:[RACSignal empty]]
            then:^{
                return [RACSignal return:x];
            }];
    }]
    concat]
    subscribeNext:^(UIRefreshControl *x) {
        NSLog(@"Is on main thread: %d",[NSThread isMainThread]);
        [x endRefreshing];
    }];

// output
// Is on main thread: 0

@kastiglione
Copy link
Member

Ah yes, it's the execution signals, not their values, that are being delivered on main. My mistake.

One option is to apply -deliverOnMainThread to the signal returned from the generator block, the other option is to apply -deliverOnMainThread before the -subscribeNext:, or whichever point you need it to be on main.

@ryanli-me
Copy link
Contributor Author

Yeah, my PR is to apply -deliverOnMainThread before the -subscribeNext:, but I think apply it in the generator block will make more sense. Thanks!

@jspahrsummers
Copy link
Member

I'm 👍 on this change. Can you please put deliverOnMainThread on its own line, though? 🙏

@jspahrsummers jspahrsummers self-assigned this May 3, 2015
@ryanli-me
Copy link
Contributor Author

Just did, glad I could help. 😁

@jspahrsummers
Copy link
Member

Great, thank you! ✨

jspahrsummers added a commit that referenced this pull request May 8, 2015
Guarantee to update refresh control on main thread
@jspahrsummers jspahrsummers merged commit d3cd58a into ReactiveCocoa:swift-development May 8, 2015
mdiep pushed a commit that referenced this pull request May 7, 2016
Guarantee to update refresh control on main thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants