question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple way to pipe one observable into another?

See original GitHub issue

Hey folks,

I went through the documentation but couldn’t find it, but my gut feeling says it’s there. Also the ConnectableObservable does not that what I want (I think?).

In my code I have something like this:

configProvider.closeBuckets().subscribe(new Observer<ClusterConfig>() {
    @Override
    public void onCompleted() {
        request.observable().onCompleted();
    }

    @Override
    public void onError(Throwable e) {
        request.observable().onError(e);
    }

    @Override
    public void onNext(ClusterConfig clusterConfig) {
        request.observable().onNext(clusterConfig);
    }
});

You can see that more or less I want to pipe all the stuff into a different observable. Something like.

configProvider.closeBuckets().subscribe(request.observable());

So I’d like to subscribe with another observable, if that makes sense?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
zsxwingcommented, May 20, 2014

Looks you are describing Subject?

0reactions
DylanSalecommented, May 22, 2014

Essentially, I am doing this (my code uses generics properly, I omitted them for brevity):

public class MyFragment extends Fragment {
    PublishSubject foo = PublishSubject.create();

    public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         addSubscription(getActivity().getHotObservable().map(etc).subscribe(foo));
    }

    public Observable getOutputObservable() { return foo; }
}

// Some other code
MyFragment frag = new MyFragment();
//then I add frag to the activity. This happens async so at some point in the future, 
//onActivityCreated will be called, but I want to use frag's observable here
//At this point, frag has not been attached to the Activity, so it has no "input" observable, thus
//the need to have the subject there. Without the subject, getOutputObservable would be null 
//and I'd have to add extra code to know when the fragment has been attached and has set up its observable.
frag.getOutputObservable().filter(func).subscribe(new Action1 etc);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rxjs One Observable Feeding into Another - Stack Overflow
For transforming items emitted by an Observable into another Observable, you probably want to use the flatMap operator.
Read more >
Passing value from one observable to another in RxJS
Passing value from one observable to another in RxJS ... The simplest solution that comes to mind for the situation is through nested...
Read more >
3 Common Mistakes I see people use in Rx and the ... - Medium
1. Taking Data out of Observables to put into other Observables. · 2. Using multiple Observable.subscribes in an expression. · 3. Not returning...
Read more >
Get started transforming streams with map, pluck, and mapTo
In this article, we are going to learn about the most common operator used to transform streams, the map operator. We will start...
Read more >
The cleanest way to write observable chains - Level Up Coding
Solution 4: break up the observable chain ... There is one alternate strategy we can use for readability. That is to break up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found