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

Operators: startFuture (StartAsync) and deferFuture (DeferAsync) #645

Closed
wants to merge 3 commits into from

Conversation

akarnokd
Copy link
Member

Issue #634

They are basically 1-2 layer deep indirections around Futures and Observables.

@akarnokd akarnokd mentioned this pull request Dec 20, 2013
53 tasks
@cloudbees-pull-request-builder

RxJava-pull-requests #577 SUCCESS
This pull request looks good

@cloudbees-pull-request-builder

RxJava-pull-requests #579 FAILURE
Looks like there's a problem with this pull request

@cloudbees-pull-request-builder

RxJava-pull-requests #580 SUCCESS
This pull request looks good

@DavidMGross
Copy link
Collaborator

Could someone give me a summary of the differences between the following
three operators:

fromFuture( Future )
from( Future )
startFuture( Future )

On Fri, Dec 20, 2013 at 6:29 AM, CloudBees pull request builder plugin <
[email protected]> wrote:

RxJava-pull-requests #580https://netflixoss.ci.cloudbees.com/job/RxJava-pull-requests/580/SUCCESS

This pull request looks good

Reply to this email directly or view it on GitHubhttps://github.com//pull/645#issuecomment-31012682
.

David M. Gross
PLP Consulting

@akarnokd
Copy link
Member Author

from(Future)

synchronously awaits the completion of the Future while in the subscribe method

Future f = ...
from(f).subscribe(observer);
// we get here only if f has completed

subsequent subscriptions will immediately receive the output of f.

startFuture(Func<Future<T>>)

It immediately calls the factory function and and returns the Observable of the call to from(Future). If the factory call fails, returns an Ebservable.error with the exception instead. This awaits the completion of the future so new subscribers may get the result immediately.

fromFuture(Func<Future<T>>)

This defers the factory function call into the subscription phase so practically every subscribing observer will get a "fresh" future.

So they are basically linked as:

Future f = ...
Func0<Future> factory = () -> someFuture

from(f) ;

startFuture == from(factory.call());

fromFuture == defer(() -> from(factory.call()));

Hope this helps.

@DavidMGross
Copy link
Collaborator

Hmmm... okay. I think I understand that, but now I'm confused at the
difference between fromFuture() and deferFuture().

On Fri, Dec 20, 2013 at 12:51 PM, akarnokd [email protected] wrote:

synchronously awaits the completion of the Future while in the subscribe method

Future f = ...
from(f).subscribe(observer);
// we get here only if f has completed

subsequent subscriptions will immediately receive the output of f

It immediately calls the factory function and and returns the Observable of the call to ```from(Future)```. If the factory call fails, returns an Ebservable.error with the exception instead. This awaits the completion of the future so new subscribers may get the result immediately

```fromFuture(Func<Future<T>>)```
This defers the factory function call into the subscription phase so practically every subscribing observer will get a "fresh" future.

So they are basically linked as:

Future f = ...
Func0<Future> factory = () -> someFuture

from(f) ;

startFuture == from(factory.call());

fromFuture == defer(() -> from(factory.call()));

Hope this helps.




—
Reply to this email directly or view it on GitHub<https://github.com/Netflix/RxJava/pull/645#issuecomment-31040678>
.

David M. Gross
PLP Consulting

@akarnokd
Copy link
Member Author

This is where it becomes full circle. The factory returns a future which returns an observable sequence that is relayed to the subscriber.

deferFuture = defer(() -> merge(from(factory.call())))

Where merge is used because from returns an observable of observable of T.

@DavidMGross
Copy link
Collaborator

Ahhh... I think I'm beginning to see the light.

On Fri, Dec 20, 2013 at 4:36 PM, akarnokd [email protected] wrote:

This is where it becomes full circle. The factory returns a future which
returns an observable sequence that is relayed to the subscriber.

deferFuture = defer(() -> merge(from(factory.call())))

Where merge is used because from returns an observable of observable of T.


Reply to this email directly or view it on GitHubhttps://github.com//pull/645#issuecomment-31052018
.

David M. Gross
PLP Consulting

@benjchristensen
Copy link
Member

Speaking with @headinthebox the history of these from Rx.Net is to support integration with async/await which Java does not have. Thus it does not seem appropriate to implement them for Java.

Anytime this functionality is needed it is trivial to do inside Observable.create.

Can you provide reasons to add these other than matching Rx.Net? If it's only to match Rx.Net then we will pass on them. They greatly complicate the API and have easier solutions by using the create/from methods that already exist.

@akarnokd
Copy link
Member Author

I can't be sure how much legacy code with Futures are out there that could be interfaced with RxJava this way. So can't give a definite reason. Maybe this and other unwanted operators could be moved under the contribution section?

benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 27, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
@benjchristensen
Copy link
Member

Merge these into #696 instead.

benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 30, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 30, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 30, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 30, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
benjchristensen added a commit to benjchristensen/RxJava that referenced this pull request Dec 30, 2013
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX#646 (comment)
- ReactiveX#645 (comment)
- ReactiveX#622 (comment)
@akarnokd akarnokd deleted the SomeMissingAsyncs branch January 13, 2014 09:58
benjchristensen added a commit to ReactiveX/RxJavaAsyncUtil that referenced this pull request Aug 29, 2014
Home for async utility functions with juc.Future, Actions, Functions etc that don’t need to be in rxjava-core.

As per discussions at:

- ReactiveX/RxJava#646 (comment)
- ReactiveX/RxJava#645 (comment)
- ReactiveX/RxJava#622 (comment)
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.

4 participants