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

Replay subject with asMaybes and take #93

Closed
thenikso opened this issue Nov 1, 2012 · 3 comments
Closed

Replay subject with asMaybes and take #93

thenikso opened this issue Nov 1, 2012 · 3 comments

Comments

@thenikso
Copy link
Contributor

thenikso commented Nov 1, 2012

I'm having trouble with a scenario like this:

RACReplaySubject *subject = [RACReplaySubject subject];
[subject sendError:[[NSError alloc] init]];

[[[subject asMaybes] take:1] subscribeNext:^(id x) {
  // I loop 4evar
} completed:^{
  // I never complete
}];

And this is because asMaybes actually is "asMaybesAndRepeatOnError" and take:1 valuesTaken goes past count.
This makes me think to the Materialize as discussed in #90

To be more specific, I'm trying to make something like this (pseudocode):

RACAble(property) 
select:^id(id x) {
    return [[<a replay subject> asMaybe] take:1]; }
switch
subscribeNext:...

The goal is to keep the outer rac alive even if the inner one fails.
If I move asMaybe after switch the replay subject builded by the RACAble macro, immediately fires the subscribable again, which is not desired.

Wouldn't be this a use case for a subscribable that convert to maybes but completes upon error?

@joshaber
Copy link
Member

joshaber commented Nov 1, 2012

-asMaybes is poorly defined. We should probably just get rid of it.

The better approach depends on what you want to do when that inner replay subject errors. You probably want to use -catch: or -catchTo: instead of -asMaybes.

For example, if you just want it to complete instead of erroring:

RACAble(property) 
select:^id(id x) {
    return [[<a replay subject> catchTo:[RACSubscribable empty]] take:1]; }
switch
subscribeNext:...

Or just yield nil:

RACAble(property) 
select:^id(id x) {
    return [[<a replay subject> catchTo:[RACSubscribable return:nil]] take:1]; }
switch
subscribeNext:...

@thenikso
Copy link
Contributor Author

thenikso commented Nov 1, 2012

Using catch solves my issue, thanks.

As a side note, this also loops indefinitely:

RACReplaySubject *subject = [RACReplaySubject subject];
[subject sendNext:@(1)];
[subject sendCompleted];
[[[subject repeat] take:1] subscribeNext:^(id x) { ... }];

@joshaber
Copy link
Member

joshaber commented Nov 1, 2012

Nice catch. I created #94 for that issue.

@joshaber joshaber closed this as completed Nov 1, 2012
andersio pushed a commit that referenced this issue Sep 22, 2016
Use `#selector` for selector
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

No branches or pull requests

2 participants