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.

OnSubscribeCombineLatest#MultiSourceProducer request method get different result?

See original GitHub issue

In request method,there is a line code ‘😮.unsafeSubscribe(s);’ and I find the unsafeSubscribe()'s note is ‘Subscribes to an Observable and invokes {@link OnSubscribe} function without any contract protection,error handling, unsubscribe, or execution hooks.’. This is my code:

Observable<Long> observable1 = Observable.interval(0, 1000, TimeUnit.MILLISECONDS)
                    .map(new Func1<Long, Long>() {
                        @Override
                        public Long call(Long aLong) {
                            return aLong * 5;
                        }
                    }).take(5);
            Observable<Long> observable2 = Observable.interval(500, 1500, TimeUnit.MILLISECONDS)
                    .map(new Func1<Long, Long>() {
                        @Override
                        public Long call(Long aLong) {
                            return aLong * 10;
                        }
                    }).take(4);
            Observable.combineLatest(observable2, observable1, new Func2<Long, Long, Long>() {
                @Override
                public Long call(Long aLong, Long aLong2) {
                    Log.i("ppppp", "combineLatest aLong = " + aLong + "   aLong2 =" + aLong2);
                    return aLong + aLong2;
                }
            }).subscribe(new Subscriber<Long>() {
                @Override
                public void onCompleted() {
                    System.out.println("Sequence complete.");
                }
                @Override
                public void onError(Throwable e) {
                    System.err.println("Error: " + e.getMessage());
                }
                @Override
                public void onNext(Long aLong) {
                    System.out.println("combineLatest Next: " + aLong);
                }
            });

I run this code and get two different results. (1) Next: 0 Next: 5 Next: 10 Next: 20 Next: 25 Next: 35 Next: 40 Next: 50 (2) Next: 0 Next: 5 Next: 15 Next: 20 Next: 25 Next: 35 Next: 40 Next: 50

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
akarnokdcommented, Apr 1, 2016

If you have a full row, that is the first time the combiner function is called.

PublishSubject<String> a = PublishSubject.create();
PublishSubject<String> b = PublishSubject.create();
PublishSubject<String> c = PublishSubject.create();

Observable.combineLatest(a, b, c, (u, v, w) -> u + v + w).subscribe(System.out::println);

a.onNext("1");
b.onNext("1");
a.onNext("2");
b.onNext("2");
b.onNext("3");
System.out.println("Full row:");
c.onNext("1");

It will print

Full row:
231
0reactions
akarnokdcommented, Apr 2, 2016

It was readable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rxjs avoid nested subscription with combineLatest
I need to fix this nested subscriptions , but i have some difficulties :-( could you help me please to find a ...
Read more >
6 Ways to Unsubscribe from Observables in Angular
In this post, I'll review the different ways you can unsubscribe from Observables in Angular apps. The Downside to Observable Subscription.
Read more >
5 helpful RxJS solutions. to everyday problems | Compendium
The combineLatest function combines an array of streams into one and emits them all whenever one of them changes. Now we have all...
Read more >
Flux (reactor-core 3.5.0)
Collect all elements emitted by this Flux until this sequence completes, and then sort them using a Comparator into a List that is...
Read more >
Using Combine
Many publishers will immediately provide data when requested by a subscriber. In some cases, a publisher may have a separate mechanism to enable ......
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