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.

No "isCompleted" or "isErrored" methods on Observable

See original GitHub issue

Hey folks,

I was currently running into the situation where I just needed a quick check if my observable is already done (and in particular failed), but I wondered why this is not exposed on the Observable - is there any specific reason?

my code was like

if (!observable.isCompleted()) {
 rescheduleIt();
}

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
headintheboxcommented, Jun 4, 2014

If you need this, your code is probably too imperative.

But more importantly, it makes no sense for cold observables like Observable.range(1, 10) because that is never completed.

Assuming observable is hot, you can implement it yourself by doing

var isCompleted = false;
val s  = observable.subscribe(x => {}, (e)=>{},()=>{ isCompleted = true; })
...
if (!isCompleted) { rescheduleIt(); }

Note it is dangerous to rely on since there is a race condition

if (!isCompleted) {
  // now it can become completed right here, so you will reschedule anyhow.
 rescheduleIt();
}
3reactions
abersnazecommented, Jun 4, 2014

If an Observer/Subscriber receives and onCompleted or onError (or doesn’t want to any more onNext for any other reason) then it should unsubscribe from the Subscription. In a way isUnsubscribed on the Subscription/Subscriber can be used as a proxy for isComplete() || isError()

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxJS - observable doesn't complete when an error occurs
The statement will be always executed regardless an error occured or not (like the finally statement in most programming languages). observer.
Read more >
My Fun with Angular Observables - TA Digital Labs
My lazy and strict friend is generous too, he does not mind if somebody wants to cancel the subscription through unsubscribe() method.
Read more >
An intro to Observables and how they are different from ...
Observer.complete('completion of delivery of all values') // this tells the subscriptions to observable is completed. No delivery is going to ...
Read more >
In Search of Better Loading and Error-handling in Angular
In this post, we'll experiment with various ways to handle loading and errors when fetching dynamic data. Our Starting Point. In my Use ......
Read more >
RxJs Error Handling: Complete Practical Guide
Using this approach, we cannot, for example, recover from the error or ... If no error occurs, the output Observable produced by catchError ......
Read more >

github_iconTop Related Medium Post

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