Observables: Complete vs finally vs done

Finally always happens whenever an observable sequence terminates (including errors); completed only happens when it terminates without errors.

Finally:

Invokes a specified action after the source observable sequence
terminates gracefully or exceptionally.

https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/finally.md

OnCompleted:

An Observable calls this method after it has called onNext for the
final time, if it has not encountered any errors.

http://reactivex.io/documentation/observable.html

“Done” isn’t an rx/observables concept. I’ve just seen it printed in examples of “Complete”https://stackoverflow.com/”OnComplete”.

Note: when you call subscribe, the syntax is usually:

observable.subscribe([observer] | [onNext], [onError], [onCompleted]);
// Like this:
observable.subscribe(
    (value) => { ... },
    (error) => { ... },
    () => { console.log('complete!'); }
);

or

observable.subscribe({
  next: x => console.log('got value ' + x),
  error: err => console.error('something wrong occurred: ' + err),
  complete: () => console.log('done'),
});

Whereas finally is handled like this:

observable.finally(() => { console.log('finally!'); })
          .subscribe(...) // you can still call subscribe

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)